I forgot the semicolon ";" in a MySQL Terminal query. How do I exit?
Solution 1
You are unaware of the 5 different quote modes of the mysql terminal. I suggest you review them:
https://dev.mysql.com/doc/refman/5.0/en/entering-queries.html
Relevant parts of the above link:
The following table shows each of the prompts you may see and summarizes what they mean about the state that mysql is in.
Prompt Meaning
mysql> Ready for new command.
-> Waiting for next line of multiple-line command.
'> Waiting for next line, waiting for completion of a string
that began with a single quote (“'”).
"> Waiting for next line, waiting for completion of a string
that began with a double quote (“"”).
`> Waiting for next line, waiting for completion of an
identifier that began with a backtick (“`”).
/*> Waiting for next line, waiting for completion of a
comment that began with /*.
In the MySQL 5.0 series, the /*>
prompt was implemented in MySQL 5.0.6.
Multiple-line statements commonly occur by accident when you intend to issue a command on a single line, but forget the terminating semicolon. In this case, mysql waits for more input:
mysql> SELECT USER()
->
If this happens to you (you think you've entered a statement but the only response is a -> prompt), most likely mysql is waiting for the semicolon. If you don't notice what the prompt is telling you, you might sit there for a while before realizing what you need to do. Enter a semicolon to complete the statement, and mysql executes it:
TLDR:
To exit, type \c
, ;
, ctrl-c
or ctrl-d
. If all of those fail, get out of the quote mode you are in by typing '<enter>
, "<enter>
, or */<enter>
Solution 2
Just type \c to clear the current input statement
Solution 3
Just type ";" and hit enter. You can use as many input lines as you like to complete a query when in command line mode. So you could do something like:
>SELECT
>*
>FROM
>table
>WHERE
>id=5
>;
if you like.
Solution 4
you could try "\q"
that worked for me
Solution 5
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.
![Kevin Katzke](https://i.stack.imgur.com/4OMLW.jpg?s=256&g=1)
Kevin Katzke
Solutions Engineer at Datadog. Recently working on Image Processing DCNNs as well as on Time Series Prediction with RNNs at Audi and Bosch. My favourite language is Python.
Updated on November 26, 2020Comments
-
Kevin Katzke over 3 years
Sometimes I forget to end my SQL query with a semicolon ";" in my Mac Terminal. When this happens, the Terminal sets a
->
at the beginning and I am not able to exit this or to run any other SQL commands.How can I exit from this?