Kevin Katzke
Kevin Katzke

Reputation: 3771

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?

Upvotes: 17

Views: 24975

Answers (6)

mikulabc
mikulabc

Reputation: 126

you could try "\q" that worked for me

Upvotes: 5

Shtutz
Shtutz

Reputation: 1

use ctrl+c and it will go to the next line.

Upvotes: -1

DerpyCoder
DerpyCoder

Reputation: 135

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.

Upvotes: 1

Eric Leschinski
Eric Leschinski

Reputation: 154003

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>

Upvotes: 31

Mike Brant
Mike Brant

Reputation: 71384

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.

Upvotes: 6

Valerio Marcellino
Valerio Marcellino

Reputation: 308

Just type \c to clear the current input statement

Upvotes: 9

Related Questions