假設我們想要恢復一個由 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中文網其他相關文章!