Home > Database > Mysql Tutorial > How can we export all data from a MySQL table into a text file?

How can we export all data from a MySQL table into a text file?

王林
Release: 2023-09-11 21:21:12
forward
1448 people have browsed it

How can we export all data from a MySQL table into a text file?

This can be accomplished with the help of the SELECT ... INTO OUTFILE statement. We illustrate it with the help of the following example -

Example

Suppose we have the following data from 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)
Copy after login

Now, the following query can export all the data in the "Student_info" table to a file named "student.txt":

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

The above query will create a file named "Student.txt" and export all the data in the "Student_info" table to the file.

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

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template