9

this is first time I am upto making a windows batch file.I wish not to do experiments first as its related to live server. I use to back up mySql database by following open cmd write

mysqldump -u user -p DBname >C:\DBname.sql

then cmd ask password

password = password

I want to make a windows batch file ,upon click I wish to perform the above functionality. Can any one please give some instructions related script of .bat file

So far I wrote this

ECHO OFF
mysqldump -u user -p DBname >C:\DBname.sql
GO
SET password = password 
Go

but still it prompts me for password . I wish password get enter automatically

4 Answers 4

15

The above was still prompting me for a password I used whats below to get it to work correctly.

"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysqldump.exe" -uroot -pDBPass DBName > C:\DBname.sql
Sign up to request clarification or add additional context in comments.

1 Comment

when you do -ppassword instead of -p password it worked as expected, upvoted!
10

The one-liner:

mysqldump -u user -p DBname --password YOURPASSWORD > C:\DBname.sql

should do it.

3 Comments

yes ,thanks , i did following ECHO OFF mysqldump -u user -ppassword DBname >C:\DBname.sql GO
great thank you. I forgot -p for password parameter. Because of my password has 'p' for first character. ;)
Could you maybe write out the whole program in your answer? I'm a beginner with .bat and it's hard for me to piece it together from this answer/question above.
1

You can use this:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" -u root -proot test > D:\DBname.sql

Please note this: -proot, the p and root must be together

Comments

0
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe" -u root -pmypassword --databases mydatabase --hex-blob > C:\mybackup.sql

Paste into a bat file, I couldnt get the plain command to work in task scheduler so used a BAT

You can omit the --hex-blob, its there incase you're using blob columns

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.