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

2 Answers 2


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, 2017 at 5:24

I only gave the name without user and password credentials.

This works:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .