怎樣恢復由 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”的資料表已恢復到名為“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)

更新日期:2020-06-20

123 次瀏覽

啟動你的 職業

完成課程即可獲得認證

開始
廣告