假设我们想要恢复一个由 mysqldump 创建的文件,那么我们可以在现有数据库中恢复,也可以在创建该文件后在新数据库中恢复。然后借助SOURCE语句,我们就可以恢复它。我们可以通过一个例子来说明:
在这个例子中,我们正在恢复名为已转储的student_info.sql。它基本上是在数据库名称“query”中。现在我们将其恢复到名为“tutorials”的数据库中。
mysql> Use Tutorials; Database changed mysql> SOURCE student_info.sql; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.45 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.05 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 7 rows affected (0.05 sec) Records: 7 Duplicates: 0 Warnings: 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)
以上是如何恢复 mysqldump 创建的文件?的详细内容。更多信息请关注PHP中文网其他相关文章!