数据库的备份和还原
1.命令行
1.1 语法:
1.1.1 备份:mysqldump -u用户名 -p密码 数据库名称 >保存的路径
1.1.2 还原:
- 1.登录数据库
- 2.创建数据库
- 3.使用数据库
- 4.执行文件:source 文件路径
C:\Users\snwan>mysqldump -uroot -proot >d://a.sql
C:\Users\snwan>mysqldump -uroot -proot db1 >d://a.sql
C:\Users\snwan>mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql> drop database db1;
Query OK, 8 rows affected (0.09 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db2 |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)
mysql> use db1;
Database changed
mysql> source d://a.sql;
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| department |
| employee |
| stu |
| student |
| tab_category |
| tab_favorite |
| tab_route |
| tab_user |
+---------------+
8 rows in set (0.00 sec)
2.图形化工具