Select*fromStudent_info;+------+---------+------ ------+------------+|id |Name |Address |Subject&"/> Select*fromStudent_info;+------+---------+------ ------+------------+|id |Name |Address |Subject&">

Home  >  Article  >  Database  >  How can we export certain fields from a MySQL table into a text file?

How can we export certain fields from a MySQL table into a text file?

WBOY
WBOYforward
2023-09-09 11:09:10771browse

我们如何将 MySQL 表中的某些字段导出到文本文件中?

This can be done by providing the column names in the SELECT … INTO OUTFILE statement when exporting data from a MySQL table to a file. We illustrate with the help of the following example-

Example

Suppose we get the following data from the table "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)

Suppose we only want to get the "id" from the above table " and "Name" columns are exported to the file, then the following query can export only the "id" and "name" values ​​in the "Student_info" table to a file named "student1.txt"-

mysql> Select id, Name from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student1.txt';
Query OK, 6 rows affected (0.07 sec)

The above query will create a file named "Student.txt" and export the values ​​of the "id" and "name" columns in the "Student_info" table to the file.

The above is the detailed content of How can we export certain fields from a MySQL table into a text file?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete