0

There are a little different to do this on Windows.

  • Create a bat file, contains mysql database backup command text.
  • Create a task in Windows Task Schedule to execute this bat file.

Then you could config this task as your wish, and do restore.

1 Answer 1

2

1: Backup Database.

@ECHO OFF
set filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%

"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe" -uroot -p123456 -hlocalhost databaseName > C:\Danny\MySql-BackUp\databaseName-%filename%.sql

Format Explain: mysqldump.exe –e –u[username] -p[password] -h[hostname] [database name] > C:[filename].sql

Run batch file, you will get a sql file contains all database info.

2:Restore database using backup sql.

Get into Mysql root path in CMD, and execute below command:

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql.exe -uroot -p123456 -hlocalhost databaseName < C:\Danny\MySql-BackUp\databaseName-201801311848321.sql
Sign up to request clarification or add additional context in comments.

2 Comments

If your bat file execute failed, maybe caused by wrong data format. You could add "echo %data%" to show your data format and add "parse" at the end of bat file to avoid command window close automatically. And then to format your own filename.
You could also set character-set for your backup sql file. Just modify bat command like this: "C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe" -uroot -p123456 --default-character-set=utf8 -hlocalhost databaseName > C:\Danny\MySql-BackUp\databaseName-%filename%.sql

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.