How to exit MySQL command prompt?
To add on to the other answer, you could simply end the current invalid query using a semicolon:
mysql> /version
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax.........
mysql> exit
Bye
c:\mysql\bin>
Or using \G
(which is supposed to make rows display vertically):
mysql> /version
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax.........
mysql> exit
Bye
c:\mysql\bin>
Of course, both options assume you have no opening quote. If you do, you must first close it off with an ending quote.
Why does ctrl-c not exit mysql input mode in Windows?
Because you have told MySQL to interpret your exit commands as valid input.
What makes the MySQL terminal hard to understand is there there are different modes for single quote, double quote, and normal mode.
So to get out of mysql input mode, you will have to do these steps:
- Get out of double quote mode.
- Get out of single quote mode.
- Get out of mysql mode.
- Exit mysql back to the default terminal.
Most basic example:
mysql> /version
->
->
->
-> \c
mysql> exit
Bye
C:\>
You never left default mode in the above example so exit commands work correctly.
Example 2 (this is what is tripping you up).
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 singlequotes: '''
-> now it will listen to your escape code: \c
mysql> exit
Bye
C:\>
While you are in single quote mode or double quote mode, no escape sequences are respected. Even Ctrl-C and Ctrl-D are ignored in these modes.
In which one of the 26 universes does Ctrl-C not stop a program regardless of mode? We may never know. Bazinga.
\q
does the job for me. Using Ubuntu Terminal.