Home  >  Article  >  Database  >  How to export mysql data

How to export mysql data

藏色散人
藏色散人Original
2019-06-01 13:38:337366browse

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';

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';

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;

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!

Statement:
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