MySQL数据备份与恢复
数据备份
备份所有数据库 mysqldump -u用户名 -p –all-databases > backup.sql
备份多个数据库 mysqldump -u username -p –databases dbname2 dbname2 > Backup.sql
备份单个数据库 mysqldump -u username -p dbname table1 table2 …tablen > backup.sql
-- 备份所有数据库
C:\wamp\bin\mysql\mysql5.7.24\bin>mysqldump -uroot -p --all-databases > C:\Users\admin\Desktop\all.sql
Enter password: ******
-- 备份单个数据库
C:\wamp\bin\mysql\mysql5.7.24\bin>mysqldump -uroot -p --databases test > C:\Users\admin\Desktop\test.sql
Enter password: ******
-- 备份单个数据库中几个表
C:\wamp\bin\mysql\mysql5.7.24\bin>mysqldump -uroot -p test students classes > C:\Users\admin\Desktop\test.sql
Enter password: ******
数据还原
mysql -u root -p [dbname] < backup.sq
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> drop database test;
C:\wamp\bin\mysql\mysql5.7.24\bin>mysql -uroot -p < c:/Users/admin/Desktop/all.sql
Enter password: ******
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+