Repeating and Editing Queries
Problem
The query you just entered contained an error, and you want to fix it without typing the whole thing again. Or you want to repeat an earlier statement without retyping it.
Solution
Use mysql’s built-in query editor.
Discussion
If you issue a long query only to find that it contains a syntax error, what should you do? Type in the entire corrected query from scratch? No need. mysql maintains a statement history and supports input-line editing. This allows you to recall queries so that you can modify and reissue them easily. There are many, many editing functions, but most people tend to use a small set of commands for the majority of their editing.[4] A basic set of useful commands is shown in the following table. Typically, you use Up Arrow to recall the previous line, Left Arrow and Right Arrow to move around within the line, and Backspace or Delete to erase characters. To add new characters to the line, just move the cursor to the appropriate spot and type them in. When you’re done editing, press Return to issue the query (the cursor need not be at the end of the line when you do this).
|
Editing Key |
Effect of Key |
|---|---|
|
Up Arrow |
Scroll up through statement history |
|
Down Arrow |
Scroll down through statement history |
|
Left Arrow |
Move left within line |
|
Right Arrow |
Move right within line |
|
Ctrl-A |
Move to beginning of line |
|
Ctrl-E |
Move to end of line |
|
Backspace |
Delete previous character |
|
Ctrl-D |
Delete character under cursor |
Input-line editing is useful ...