Loading...
X

How to quickly clear a command line in the MySQL (MariaDB) client

How to quickly clear the MySQL (MariaDB) command line prompt

When actively working with the DBMS at the command line prompt, from time to time anyone makes mistakes. For example, an invalid query expression was entered: in the wrong terminal window, or before selecting a database, or some other error.

In the Linux terminal, this problem is solved in an elementary way – just press Ctrl+c. This key combination stops the running utility, but if no utility is running, then it jumps to the next line, and everything entered at the current command prompt becomes invalid and discarded.

If you enter an invalid expression in the MySQL (MariaDB) client, pressing Ctrl+c will cause the MySQL (MariaDB) client to exit. That is, of the two options described above (the running utility stops and the prompt is cleared), the first one will occur.

How to clear an erroneous expression in the MySQL (MariaDB) client

Instead of deleting a line one character at a time using the “Backspace” key, you can use a special MySQL (MariaDB) client command:

\c

That is, if you find that you have entered incorrect data, then simply add the characters “\c” to the already typed line and then press the “Enter” button.

Immediately after that, the cursor will jump to a new line, and the entered data will not be executed as an SQL query. That is, the current input statement will be cleared.

Note: If you have already entered a separator, which by default is “;” (semicolon), then such an expression will still be executed!

How to quickly delete incorrectly entered data in the command line of the MySQL (MariaDB) client

In fact, shell shortcuts (e.g. Bash, ZSH) may also work in a command line client.

For example, if your MySQL (MariaDB) client is running in Bash, then you can use the keyboard shortcut Ctrl+u to completely delete the line from the current cursor position to the left side. Moreover, in this case, the presence of the MySQL query separator (semicolon) does not affect in any way – the line will be successfully deleted anyway.

Note: in ZSH, the Ctrl+u key combination deletes the line completely – not only from the cursor to the left side, but the entire line.

To delete a line from the current cursor position to the end of the line to the right, use the keyboard shortcut Ctrl+k.

To delete a line from the cursor to the left side by individual words, use the keyboard shortcut Ctrl+w.

Note: The last keyboard shortcut also affects the clipboard because it puts the cut word on the clipboard.

A couple more useful keyboard shortcuts that work in both Bash and MySQL clients:

  • Ctrl+a – moves the cursor to the beginning of the line
  • Ctrl+e – moves the cursor to the end of the line

Conclusion

In this short article, we looked at how to quickly erase what you have written in MySQL prompt.

In short, the most important thing is not to use Ctrl+c, as this will close the current connection session to the MySQL server.

As a MySQL built-in command, you can type “\c” and press the “Enter” button.

Or use the keyboard shortcut Ctrl+u.

By the way, in order not to accidentally press Ctrl+c while connecting to the MySQL server, you can develop the habit of erasing lines with Ctrl+u and when working with the Bash console, instead of using Ctrl+c.

Another keyboard shortcut you may find useful is Ctrl+l to clear the console window (without clearing the current typed expression).


Leave Your Observation

Your email address will not be published. Required fields are marked *