Home > Database > Mysql Tutorial > How to export mysql data

How to export mysql data

藏色散人
Release: 2019-06-01 13:38:33
Original
7400 people have browsed it

How to export mysql data

MySQL is one of the most popular relational database management systems. In MySQL, we can use the SELECT...INTO OUTFILE statement to simply export data to a text file.

Use the SELECT ... INTO OUTFILE statement to export data

In the following example, we export the data of the data table demo_tbl to the /tmp/demo.txt file:

mysql> SELECT * FROM demo_tbl 
    -> INTO OUTFILE '/tmp/demo.txt';
Copy after login

You can set the specified format of data output through command options. The following example is to export CSV format:

mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/demo.txt'
    -> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    -> LINES TERMINATED BY '\r\n';
Copy after login

In the following example, a file is generated, and each value is separated by commas.

This format can be used by many programs.

SELECT a,b,a+b INTO OUTFILE '/tmp/result.text'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;
Copy after login

The above is the detailed content of How to export mysql data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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