0

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.

Ghost Answer
  • 1,458
  • 1
  • 17
  • 41

1 Answers1

1

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;
peterm
  • 91,357
  • 15
  • 148
  • 157
  • I just tried by exit from MySQL and put the backup command but I got a new error like " -bash: !JW8.: event not found". – Ghost Answer Sep 24 '13 at 07:37
  • @GhostAnswer First of all that means that your question is answered :). Now these characters I guess are part of your password? If your password contains characters other than alpanumeric ones you have to put your password in double quotes and place it right after `-p` **(no spaces)**. See updated answer. – peterm Sep 24 '13 at 07:42
  • I will check and tell you. – Ghost Answer Sep 24 '13 at 07:53