假设如果要还原由mysqldump创建的文件,则可以在创建后在现有数据库或新数据库中还原。然后借助SOURCE语句,可以将其还原。我们可以通过一个例子来说明:
在此示例中,我们将还原已转储的名为student_info.sql的表。它基本上是在数据库名称“查询”中。现在,我们将其还原到名为“ tutorials”的数据库中。
mysql> Use Tutorials; Database changed mysql> SOURCE student_info.sql; 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)