1

i am executing query for importing sql dump in ubuntu

 mysql -u username - p passsword databasenme < var/www/sql.sql;
error: 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 -u
1
  • exit first if you have login in mysql from your terminal. fire your command from your home. hit exit command first. Commented Feb 1, 2016 at 12:25

4 Answers 4

3

There should not be any blank space between -p and the password.

mysql -u username -p<PASSWORD HERE> databasenme < var/www/sql.sql;

UPDATE:

I assumed you weren't logged in to mysql already. If you are, you should exit from mysql console and then retry.

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

Comments

3

You can import .sql file using :

mysql -u <user> -p<password> <dbname> < mysqlfile.sql

Note: There shouldn't space between -p and <password>

Reference: http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html

Time taken for importing huge files most importantly it takes more time is because default setting of mysql is "autocommit = true", you must set that off before importing your file.

First open MySQL:

mysql -u root -p

Then, You just need to do following :

mysql>use your_db

mysql>SET autocommit=0 ; source the_sql_file.sql ; COMMIT ;

2 Comments

i have relogged to database and use my database but when i fire query it give same error
If you set a password for your user, you have to add -p parameter, regardless if you specify it on command line or in virtual mode. mysql -u yourUserName -poptionallyYourPassword_no_space_here_if_you_specify_one -h localhostOrWhatever yourDatabaseName < b3.sql
2

You are logged in to mysql. press ctl+z to exit and try again.

Comments

1

don't write user's password on this line, type only flag -p , and in new line enter password:

$ mysql -u user -p database_name < your_file.sql
Enter password: 

EDIT:

Check .sql file for syntax, maybe have a syntax error in the file.

3 Comments

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
@Raj, can you show .sql file, i think you have a syntax error in the file. Check file for syntax
@Raj, Click the green outlined checkmark to the left of the answer that solved your problem. This marks the answer as "accepted", and by extension the question as "has an accepted answer". p.s It is necessary for those who are faced with the same problem.

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.