Error while taking backup with mysqldump in mysql command line

12,614

Solution 1

mysqldump is not a MySQL command, it is a command line utility. You must call it from your shell command line.

Solution 2

The problem is you are executing the command from a MySQL prompt instead of a Linux shell. Exit the mysql command line and run the command from a OS shell (remove the semicolon at the end)

Solution 3

In your command, you can't have a space between -p and the password. Also, mysqldump has to be run on the command line, not in a mysql shell.

Try this on your command line

mysqldump -u username -ppassword databasename > backup.sql

Solution 4

I didn't understood what the others was trying to say until i saw this question.

The thing is, you can't access the "mysql.exe" and put the mysqldump in it. The "mysqldump.exe" is another file, so you have to execute it from the command line of the OS passing parameters to the execution.

So, in the DOS (on Windows, of course), supose that you're in the directory: "C:\xampp\mysql\bin", then you can call the following command:

mysqldump -u root -p test > test.sql

You could also call it like this, so you can explicitly see that you're executing a file:

.\mysqldump.exe -u root -p test > test.sql

If it can be more crystal clean, you would see that line in the DOS:

c:\xampp\mysql\bin>.\mysqldump.exe -u root -p test > test.sql

Ps: in that code you would be asked to inform the password after executing. That is, indeed, the recomendation that the "mysqldump.exe" gives you if you put the password directly in the dump line.

Ps 2: if you're using the default settings of the root user (i.e. with empty password), you need to just press "Enter" when asked to inform the password.

Ps 3: the "test.sql" will be created in the same directory of the "mysqldump.exe". In this example, in: "C:\xampp\mysql\bin".

Solution 5

Type this in your command line interface NOT in MYSQL command line:

mysqldump -u username -ppassword databasename > backup.sql

For example, if username is 'root', password is 'abcdefg', and the database name is 'mydatabase', then the syntax is:

mysqldump -u root -pabcdefg mydatabase > backup.sql

backup.sql is the name of the file in which your backup will be stored so you can have any name.

Share:
12,614
harshakasireddy
Author by

harshakasireddy

I'm UI Developer. Love working on HTML, CSS, jquery, Responsive web design and Liferay theme development.

Updated on June 05, 2022

Comments

  • harshakasireddy
    harshakasireddy almost 2 years

    Hello I'm trying to take backup from mysql command line client. I'm using mysqldump to take backup with username and password. Following is the command I'm using for backing up the database.

    mysql> mysqldump -u username -p password databasename > backup.sql;
    

    I'm 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
    dump -u username -p password fms > backup.sql' at line 1
    

    Though the command seems to be correct, still i'm getting error. Please let me know is there any other way taking backup from mysql command line.

    Thanks in advance.

  • Timur
    Timur over 12 years
    The same way you are accessing it to run mysql -u username -ppassword command - via SSH
  • harshakasireddy
    harshakasireddy over 12 years
    I've tried that also, but of no use same error I'm getting. How do I run mysqldump in command line? Please let me know. Thanks for replaying.
  • hawk
    hawk over 10 years
    doesn't add anything to existing answers.
  • gordon_freeman
    gordon_freeman almost 3 years
    This actually solved the problem for me. Using --password=PASSWORD made all the difference and worked perfectly...