Mysql automatic backup and restore method

  • 2020-05-10 23:03:59
  • OfStack

1. Automatic backup: save the following code as *.bat batch script, and then add Windows timed jobs, such as 2 am every day:
set s=%date:~0,4%%date:~5,2%%date:~8,2%%time:~1,1%%time:~3,2%%time:~6,2%
mysqldump -u root -ppassword databasename > d:\databasename_%s%_bak.sql

Note: databasename is the database name password is the database password, the system automatically backup to the specified directory with the current date and time.

2. Restore database: mysql-u root-p databasename < d:\databasename.sql

Related articles: