We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How do you create a .bat file to run a MYSQLDUMP on all Databases?

Medium Priority
2,671 Views
Last Modified: 2012-05-11
I am trying to create a .bat file that will run the mysqldump.exe file and do a dump of the database to c:\mySqlDumps folder.  I can get this to work manually from the command prompt with the following:

mysqldump --all-databases  >  c:\mySqlDumps\mySQLBugDump.sql

However, I would like a .bat file for this as I plan on setting up a scheduled job to run the .bat file and have our backup software run a backup of the dump file.  The script I have in my .bat file is:

@echo off START C:\program files\mysql\mysql server 5.1\bin\mysqldump.exe --all-databases > C:\mysqldumps\mySQLBugDump.sql;

This produces the mySQLBugDump.sql file in the c:\mysqldumps directory but it is only 1KB in size (cpmpared to 30MB when I run the mysqldump command manually).

Any help resolving this would be greatly appreciated.  Thanks!
Comment
Watch Question

Top Expert 2011

Commented:
- spaces between filename is not recognize in DOS (command prompt). you need to wrap it with double quotes "

@echo off START "C:\program files\mysql\mysql server 5.1\bin\mysqldump.exe" --all-databases > C:\mysqldumps\mySQLBugDump.sql

- if you already have the double quotes and its still error. remove the @echo off. run the BAT file manually from command prompt to see if any errors being prompt on the screen (don't double click the BAT from windows explorer).
CERTIFIED EXPERT
Top Expert 2012

Commented:
Please request that the MS SQL Server zone be removed as it does not apply to your question.

Author

Commented:
@ OP_Zaharin

I ran the command with the double quotes from the command prompt and it also produced the file but only 1KB in size.

I then removed the @echo OFF and it gave an error:

"The System cannot find the file --all-databases".  I have pasted a screenshot below of the error.

Error message
This error is strange because when I am in the bin directory of my MySQL installation and run the command //// mysqldump --all-databases  >  c:\mySqlDumps\mySQLBugDump.sql //// from the command prompt it produces the a 30MB file containing all my database info.  There has to be a way for the.BAT file to run and produce the 30MB file with all the database info too.

@ acperkins - Sorry, I will remove from MS Sql zone
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
@ OP_Zaharin - awesome... it is working.  Huge thanks!
Top Expert 2011

Commented:
great! no problem tiger :)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.