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?
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>
Just type \c to clear the current input statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With