3

I am connecting to database mysql using command prompt using below command

mysql -h localhost -u test -ptest test;

But i am getting following error:-

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 'mysql
 -h localhost -u test -ptest test' at line 1

I have done a lot of googling but could not find the reason behind this problem. Any help?

3
  • That error looks like you're already in mysql. Just type a query like SHOW DATABSES. Commented Mar 31, 2014 at 12:50
  • you need to select db first with this command use something_db Commented Mar 31, 2014 at 12:51
  • 1
    Hey can you accept one answer if you found any of this correct. Commented Apr 17, 2014 at 4:26

4 Answers 4

4

It seems you are executing the statement at mysql command line console but not at system shell prompt.

The statement

mysql -h localhost -u test -ptest test;

is for system shell prompt.

And while running at command prompt, you don't need to terminate the command by a semi colon.
And for suppressing use of password at command line,

change

-ptest

to

-p

It then prompts you to input your password.

Sign up to request clarification or add additional context in comments.

Comments

3

You need to run that command (which starts the mysql shell) from the command prompt.

You are trying to run it inside the mysql shell.

Comments

3

First make sure your command line doesnt show

mysql> 

prefix. if it shows you are already in the mysql console. you have to type the command outside the mysql console.

mysql -h localhost -u test -ptest

That will fix you issue. Refer Mysql documentation for more information

http://dev.mysql.com/doc/refman/5.0/en/connecting.html

Thanks.

Comments

-2

mysql -u root -p -h localhost

then command would ask for password, input it and you can logged into mysql server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.