假設我們想要恢復一個由 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 創建的文件?的詳細內容,更多請關注www.92cms.cn其它相關文章!