Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you clear an unexecuted MySQL query from the command line?

Suppose you're typing a command line query into a MySQL database and you need to cancel out and start over. From a bash shell you could just type ctrl-c and get a new prompt. In MySQL, ctrl-c would exit the client and return you to the shell.

For example, I have a long, complex SELECT statement typed in but I haven't yet hit return. I realize that I don't want to send the command but I want to have the command on-screen so I can use it as a reference. I'd like to bail out without quitting MySQL. Any ideas?

Key point: the command hasn't yet been executed.

like image 905
Logan Avatar asked Jan 10 '12 22:01

Logan


People also ask

How do I clear the command in MySQL?

To clear the console, you need to add the \! symbol before the clear command. Alternatively, you can also use the CTRL + L command to clear the screen. If you're accessing MySQL from the Command Prompt in Windows OS, then you need to replace the clear command with the cls command.

How do I clear the SQL command line?

The Clear command clears the screen of the SQL*Plus application window and the screen buffer. Shift+Del is the keyboard shortcut for the Clear command.

How do you exit a query?

Use either of these keyboard shortcuts: Ctrl+C or Ctrl+D . These can be used to instantly exit any program that is running within a command prompt.


1 Answers

Type \c.

When you start up MySQL, you'll likely see this message:

Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 

The "buffer" that it's referring to is the command/query buffer.

like image 84
ruakh Avatar answered Sep 23 '22 23:09

ruakh