To exit the mysql
command line client program, you need to issue an exit
or quit
command as follows:
mysql> exit
Bye
nsebhastian@fn-mac ~ $ # back to the command line
However, there are times when you enter the mysql
prompt and can’t exit normally because MySQL thinks you are still issuing a query.
In the following example, I mistakenly typed SELECT
and hit the ENTER
key, causing the mysql
client program to think I’m issuing a multi-line command.
When I run the exit
command, I’m still inside the program as follows:
mysql> SELECT
-> exit
->
This is because MySQL allows you to create a multi-line statement to run from the command line.
To stop this multi-line prompt mode, you need to issue the \c
command to clear the current input statement:
mysql> SELECT
-> exit
-> \c
mysql>
The \c
command cancels the current input and returns you to mysql
prompt.
Alternatively, you can also send a semicolon ;
to mysql
so execute the current input.
It will probably cause an error, but it will take you back to the empty prompt:
mysql> SELECT
-> exit
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'exit' at line 2
mysql>
Once you’re back in the empty prompt, you can run the exit
command again.
Finally, if all else fails, you can try exiting mysql
command line by using the CTRL + D
command.
The command should terminate the current mysql
session and return you to the command line prompt.