I'm playing with mysql on my localhost.
Everytime I write some commands to console it starts to print "->" all the time and doesnt react to any commands except "\c" which goes back to mysql>
It looks like that:
mysql> show binary logs
->
->
->
and keeps printing "->" whenever i press Enter
Any ideas?
The semicolon is used to terminate statements in mysql.
SELECT id FROM users LIMIT 0,1; SELECT username FROM users LIMIT 0,2;
But there are some mysql command in which semicolon can be omitted.
Command provided by help like: clear, help, print, quit, use, etc
Related
How do I recover from the below? I need to get back to the maria prompt, i've tried exit and quit neither work. Currently just using ctrl-c which required me to log back in to mysql.
MariaDB [(none)]> DROP DATABASE drupal_db
->
You can do it with \c
It will move your cli to previous state
you don't have to have the ; on the same line as your command so you can just put it on the next line by itself.
If you find in some place you've made an error like dropping a single or double quote you can use \c to exit to the next line of the shell.
You can't. Your only option is to end the query and [Ctrl]+[C] out.
See this.
'> 'c/
-> ;
I just learned from above me name cctan. thanks.
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?
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.
You may give '; on the prompt to come out of that without exiting MySQL.
If this does not work, try a ' and then ';
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?
'> indicates that you added an extra single quote in your query. To end the statement, close the open single quote by typing ';
I prefer to do it using '\c' to clear wrong commands which is also suggested by mysql itself.
In your case you should
Close the string with " (or')
Use \c to clear the command.
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:\>
Just end the command with a semicolon ";". MySQL will display an error message and let you continue.
I got this done with ' then ; then press ENTER, without that semicolon it doesn't work in my case.
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.
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.
I find myself constantly typing in long commands such as:
mysql> SELECT Cust_Num, Cust_Name_Full, Email FROM customers;
Is there a way to save this command as, say, "CInf" and execute it with that simple shortcut command like this:
mysql> CInf; ( = mysql> SELECT Cust_Num, Cust_Name_Full, Email FROM customers; )
I'm thinking of something analogous to a DOS batch file, where you can simply type the name of the batch file, without even needing the .bat extension.
Also, where do I store these mysql "batch files" (note: these aren't .bat files to be run from a command window, these are run from the mysql> prompt). With DOS I'd have a C:/bat folder and I'd put C:/bat in the path environment variable. How do I do a similar thing for mysql?
Mysql doesn't have "macros", but if your statements are select queries (like your example) you can create views:
create view clnf as
SELECT Cust_Num, Cust_Name_Full, Email
FROM customers;
Then to use
select * from clnf;
The other approach is to store your SQL in files, then from the mysql prompt use the source command:
mysql> source file_name
which executes the contents of the SQL file as if you had pasted it in to the window.
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
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.
you could try "\q" that worked for me
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.
use ctrl+c and it will go to the next line.
Note: I'm using a bash shell on a nearly-fresh osx 10.6 install. This doesn't seem to happen to a friend who is on zsh
I'm used to Postgres, so I often instinctually type
\d tablename
instead of
desc tablename ;
When I do this, the mysql client is not very happy
mysql> \d items
mysql> ;
-> desc items;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
->
notice how my prompt changes after the 'oh crap' moment. It seems to lock into this routine where all sql commands are considered to have invalid syntax.
i haven't figured out a sequence yet to escape this yet; nor have i figured out what is going on.
has anyone else encountered this, and knows how to get out of it ? the only fix i've found is to ctrl-c and start a new mysql connection - and that's just not a proper fix.
In MySQL, \d changes the query delimiter, which is normally ;. So you've actually changed your delimiter to items. For instance, try doing this:
\d items
desc items items
select 1 items
Fun times.
To change it back to semicolon, just do \d ;
\d changes the statement delimiter.
You need to change it back to ;
But you can't end a statement until you type tablename
so try typing tablename followed by \d ;
Personally ctrl-c up-arrow enter seems easier. Especially since mysql still remembers your command history between sessions.