Kiwizoom
Kiwizoom

Reputation: 443

Can't quit incorrect mySQL command line

When you type a command into mySQL the wrong way, mySQL won't run the command. Instead of giving an error it sometimes gives an endless list of:

'>
'>
'>
'>

each time you enter something, no matter what input you give it (besides using quit command). I'd like to stay logged in though, so quitting, logging back in and retrying the command with different syntax is very annoying.

Is there a shortcut to just quit a line if it bugs out and stay in the connection?

Upvotes: 7

Views: 19215

Answers (10)

ruyelpequenocid
ruyelpequenocid

Reputation: 55

As for the people suggesting to use semicolon (;) to get out, that's fine, but I'd be cautious about just throwing the semicolon just anywhere. That semicolon will execute the query, even if the user had realized midway that he/she did not want to do so...

Example (table name is "species"):

mysql> drop table species
-> ;
Query OK, 0 rows affected (0.003 sec)

And just like that, the table is gone, of course. Just be careful.

Upvotes: 0

Utkarsh Singh
Utkarsh Singh

Reputation: 21

mysql> hello
    ->
    -> look dash is on the left"
    "> In doublequote mode now, because doublequote above
    "> adding another doublequote breaks you out: "
    -> look a single quote ' here
    '> in single quote mode now.
    '> get out, in, then out again with three single quotes: '''
    -> now it will listen to your escape code: \c
mysql> exit
Bye

C:\>

Upvotes: 1

himanshu rathi
himanshu rathi

Reputation: 51

If semi-colon ';' does not terminate a query, just type '\c' and the command line will clear everything up, and be ready to take a new query.

Upvotes: 0

Learner
Learner

Reputation: 99

I prefer to do it using '\c' to clear wrong commands which is also suggested by mysql itself.

In your case you should

  1. Close the string with " (or')
  2. Use \c to clear the command.

example

Upvotes: 3

outerSpace
outerSpace

Reputation: 137

'> indicates that you added an extra single quote in your query. To end the statement, close the open single quote by typing ';

Upvotes: 2

Albert
Albert

Reputation: 134

I got this done with ' then ; then press ENTER, without that semicolon it doesn't work in my case.

Upvotes: 0

alphojo
alphojo

Reputation: 630

You may give '; on the prompt to come out of that without exiting MySQL.

If this does not work, try a ' and then ';

Upvotes: 4

Phylogenesis
Phylogenesis

Reputation: 7880

As per my comment above, the prompt '> indicates that the MySQL shell is in the middle of a string and is waiting for you to close it.

Typing ' and pressing enter closes the string allowing the interpreter to carry on.

A similar prompt shows on various UNIX/Linux shells when a string hasn't been terminated correctly.

Upvotes: 16

martintama
martintama

Reputation: 193

You should always terminate SQL commands with a semicolon. As soon as you realize you made a mistake, enter ";" to finish that command and mySQL will warn you that the command was incorrect.

Then you can write your query again. Is that what you were looking for?

Upvotes: 3

Taras Kinash
Taras Kinash

Reputation: 61

Just end the command with a semicolon ";". MySQL will display an error message and let you continue.

Upvotes: 0

Related Questions