In Ubuntu server 16.04 xenial in a LEMP stack I executed mysql -u root -p (then root's password), and then, when inside the mysql shell:

mysqldump --databases "${domain}" > test.sql

but for some reason this fails:

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 'mysqldump --databases MY_DB_NAME > dump.sql' at line 1

Why this simple mysqldump command fails?


Executing the same command outside the Mysql CLI, fails as well:

mysqldump --databases "${domain}" > test.sql

mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect


mysqldump is a program. It is not a SQL statement. You don't run it at a mysql> prompt -- you run it from a system shell prompt.

  • Outside execution fails as well, please see update. Dec 10 '17 at 5:24

I only gave the name without user and password credentials.

This works:

mysqldump -u root -p"${rpsw}" "${domain}" > test.sql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.