6

I am trying to backup my database and keep getting 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 '$ mysqldump -u root -p chandlers > backup_db.sql' at line 1

I am using the following command to launch the backup :

$ mysqldump -h localhost -u root -p chandlers > backup_db.sql

edit>>>> This is how I connect to the db, this is a shortcut I have setup to open a command line :

C:\server2go\server2go\server\mysql\bin\mysql.exe -h localhost -P 7188 -u root

This works fine and connects, I have tried creating another like this >>

 C:\server2go\server2go\server\mysql\bin\mysqldump.exe $ mysqldump -h localhost -P 7188 -u root -pchandlers > backup_db.sql

but I am getting an access denied error now.

6
  • you are running this from the command line, not from the MySQL console, right? The error suggests you are within the console. Commented Jan 4, 2012 at 10:58
  • ah I see I thought this was ran from the mysql console, I will try from the command line.... Commented Jan 4, 2012 at 11:06
  • if i run it from the command line i get the following error : Commented Jan 4, 2012 at 11:08
  • C:\Users\Iain>$ mysqldump -h localhost -u root -p chandlers > backup_db.sql '$' is not recognized as an internal or external command, operable program or batch file. Commented Jan 4, 2012 at 11:09
  • You type it without the $ sign (This is just to show that it's a console command) Commented Jan 4, 2012 at 11:10

3 Answers 3

7

you can use mysqldump to backup mysql database.

Below is the script example to backup mysql database in command line:-

$ mysqldump -h localhost -u username -p database_name > backup_db.sql

If your mysql database is very big, you might want to compress your sql file. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.

$ mysqldump -u username -h localhost -p database_name | gzip -9 > backup_db.sql.gz

If you want to extract the .gz file, use the command below:-

$ gunzip backup_db.sql.gz
Sign up to request clarification or add additional context in comments.

Comments

3

You seem to be calling mysqldump from within mySQL, which is incorrect - it's a separate executable.

Call it from the command line instead.

Comments

0

I think it should be $ mysqldump -h localhost -u root -pchandlers > backup_db.sql. Otherwise it seems fine to me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.