Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I forgot the semicolon ";" in a MySQL Terminal query. How do I exit?

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?

like image 656
Kevin Katzke Avatar asked Sep 11 '12 16:09

Kevin Katzke


2 Answers

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>

like image 90
Eric Leschinski Avatar answered Sep 21 '22 19:09

Eric Leschinski


Just type \c to clear the current input statement

like image 36
Valerio Marcellino Avatar answered Sep 22 '22 19:09

Valerio Marcellino