我們如何將全部資料從 MySQL 表匯出到文字檔案中?


藉助 SELECT … INTO OUTFILE 語句可以完成此項操作。我們透過以下示例來說明這一點 −

示例

假設我們從表‘Student_info’中獲取了以下資料

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  |
+------+---------+------------+------------+
6 rows in set (0.07 sec)

現在,以下查詢可以將表‘Student_info’中的所有資料匯出到名為‘student.txt’的檔案中

mysql> Select * from student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student.txt';
Query OK, 6 rows affected (0.01 sec)

上述查詢將建立一個名為‘Student.txt’的檔案,並將表‘Student_info’中的所有資料匯出到其中。

更新於: 2019 年 7 月 30 日

659 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.