mysql command line help (windows) - mysql

i'm trying to do some practices on command line..
as you see in the pic the command is not triggering. i'm pressing Enter. (as described in practicing book)

End a command with a semicolon ;
CREATE DATABASE deneme;
As long as it keeps printing the -> prompt on new lines, it is expecting the ; terminator.

Use ; as stated.
This is a good example of why it is good practice to always end your SQL statements with a semicolon. It's a good habit to get into.

just type
;
at the end of the line
:-)

Related

Forgot to type ; at end of mysql statement, how to go back?

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.

MySQL label statement not recognized in PROCEDURE declaration

I'm trying to use a label statement in the MySQL exactly as described in doc.
I permanently get an error on the colon behind label :
What is wrong?
I already tried XAMPP with the MariaDB as well as WAMP with the MySQL. I try as simple procedure as possible. From SQL tab in phpMyAdmin as well as from file script in Import. All the same : Unexpected character near ":".
I found issue that the TAB in the procedure definition may cause problem. I have not there any TAB. I tried loop and LOOP, begin vs. BEGIN.... still same... Please help.
You have END LOOP try changing it to END LOOP loop1; see MySQL document.
Your code is confirmed to work fine in MySQL 5.6 -- here's a SQL Fiddle: http://sqlfiddle.com/#!9/c00911/1. I also suspect the phpMyAdmin client.
Try putting the label on its own line, or taking the numeric out of the label (take the word loop out of it, too -- maybe it's parsing it funny). Call it var_counter maybe.

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?
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 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?
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.

MySQL Workbench error messages

I'm trying to apply a routine to a database using MYSQL workbench but I'm having a few problems.
In the first image below, you see the mysql I'm using. This mysql has worked for someone else (i.e. the author of the book I'm following), but when I enter it, there's three error warnings (the Xs in the red boxes).
The other two images below show what happens after I hit apply the first time(showing me the SQL to be applied on the database), and then the second time (producing the error message)
Can anyone see how to fix this problem?
Note, the code that's being entered is a formula to calculate distance between two points, but, as said, it's worked for the author of the book I'm using (Larry Ullman's PHP 5)
I think it's to do with your DELIMITER declaration missing.
You need to add:-
DELIMITER $$ on line 1 before your function.
Then remove the space from END $$ so it becomes END$$