mysqlmysql-backup

Use mysqldump backup and restore Mysql database on Windows batch file


There are a little different to do this on Windows.

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


Solution

  • 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