如何还原由mysqldump创建的文件?
假设我们要还原一个由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”表已还原到名为“教程”的数据库中。
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)
广告