MySQL 如何恢复由mysqldump创建的文件?
如果我们想恢复由mysqldump创建的文件,可以在现有数据库中或在创建它之后的新数据库中进行恢复。然后我们可以使用SOURCE语句来恢复它。我们可以通过一个例子来说明:
阅读更多:MySQL 教程
例子
在此示例中,我们正在恢复名为student_info.sql的表,它已被转储。它最初在数据库名“query”中。现在,我们将其恢复到名为“tutorials”的数据库中。
mysql> Use Tutorials;
已更改数据库
mysql> SOURCE student_info.sql;
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响,1个警告(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.45秒)
查询OK,0行受影响(0.00秒)
查询OK,0行受影响(0.05秒)
查询OK,0行受影响(0.00秒)
查询OK,7行受影响(0.05秒)
记录:7 重复项:0 警告:0
现在,使用以下语句,我们可以看到“student_info”表已恢复到名为“Tutorials”的数据库中。
mysql> Show tables;
+---------------------+
| Tables_in_tutorials |
+---------------------+
| rtgs |
| student_info |
+---------------------+
2 rows in set (0.00 sec)
mysql> Select * from Student_info;
+------+---------+------------+------------+
| id | Name | Address | Subject |
+------+---------+------------+------------+
| 101 | YashPal | Amritsar | History |
| 105 | Gaurav | Chandigarh | Literature |
| 125 | Raman | Shimla | Computers |
| 130 | Ram | Jhansi | Computers |
| 132 | Shyam | Chandigarh | Economics |
| 133 | Mohan | Delhi | Computers |
| 150 | Saurabh | NULL | Literature |
+------+---------+------------+------------+
7 rows in set (0.00 sec)