MySQL data backup mysqldump and restore mysql
First, manual backup and restore:
1. Back up mysqldump manually. This command is executed on the cmd console:
Mysqldump-uroot-proot database [Table 1, Table 2] > File path
Mysqldump-uroot-proot tmp > d:/tmp.bak
Mysqldump-uroot-proot tmp student > d:/tmp.student.bak
2. Back up multiple databases
Mysqldump-u username-p-- databases dbname2 dbname2 > Backup.sql
The-- databases option is added, followed by multiple databases
Example: backing up test mysql database
Mysqldump-u root-p-- databases test mysql > D:\ backup.sql
The syntax for the mysqldump command to back up all databases is as follows:
Mysqldump-u username-p-all-databases > BackupName.sql
Example:
Mysqldump-u-root-p-all-databases > D:\ all.sql
3. Restore and execute mysql manually. This command is executed in the cmd console:
Mysql-u root-p [dbname]
< backup.sq mysql -u root -p < C:\backup.sql 4、手工还原执行source,这个指令在mysql客户端执行: mysql>Source d:\ tmp.student.bak
Second, regular backup:
1. Back up regularly under windows:
(1) create a bat file, mysqltask.bat, which contains the following contents:
Cd c:\ mysql\ bin
Mysqldump-uroot-proot tmp student > d:/tmp.student.bak
Note:
If there are spaces in the file path directory of mysqldump, then the path must be in double quotes "", that is, cd "c:\ mysql aaa\ bin"
Variable file name:
Set yy=%date:~0,4%
Set mm=%date:~5,2%
Set dd=%date:~8,2%
Set hh=%time:~0,2%
Set hh=%hh: = 0%
Set mn=%time:~3,2%
Set ss=%time:~6,2%
Set filename=%yy%%mm%%dd%%hh%%mn%%ss%.bak
(2) make mysqltask.bat into a task and schedule it regularly, usually at 2: 00 in the morning.
Control Panel > Task schedule > add Task schedule > browse and select mysqltask.bat > 2:00 every day