Search code examples
mysqldatabase-backups

Got an error on mysql database backup time


I have mysql database (mysql Ver 14.14 Distrib 5.5.28, for Linux (x86_64) using readline 5.1) on my host server. I want to take backup using SSH. So I login by root user and go to mysql and write the command as below

mysql> mysqldump -u username -p password --opt  dbname > filename.sql;

but this didnot work for me and gave me and error like

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 --u username -p password --opt  dbname > filename.sql;' at line 1

Can any one provide me a solution to me to make a backup.

I am making a backup on server directory.


Solution

  • Your problem is that you're trying to execute mysqldump from the mysql CLI.

    mysql> mysqldump ...
    ^^^^^^
    

    First exit mysql

    mysql> exit
    Bye
    username$
    

    and then in the command prompt start mysqldump on its own

    $ mysqldump -uusername -p"password" --opt  dbname > filename.sql;