Home > database >  sql
sql

Time:09-21

1, the export table is CSV format

Will be created before any export a MySQL table, and is the CSV format

Use the SELECT... Export data INTO OUTFILE statements
The following example we will data table runoob_tbl export data to/TMP/runoob. TXT file:

Mysql> SELECT * FROM runoob_tbl - & gt; INTO OUTFILE '/TMP/runoob. TXT';

You can use the command options to set the specified format of data output, the following instance for the export CSV format:

Mysql> SELECT * FROM passwd INTO OUTFILE '/TMP/runoob. TXT' - & gt; FIELDS TERMINATED BY ', 'ENCLOSED BY' "' - & gt; LINES TERMINATED BY '\ r \ n';



In the example below, generates a file, each value with a comma, this format can be used by many programs,

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


The SELECT... INTO OUTFILE statement has the following attributes:
1, the LOAD DATA INFILE is the SELECT... INTO OUTFILE inverse operation, SELECT syntax, in order to a database of data to a file, use the SELECT... INTO OUTFILE, in order to read back to the database file, use the LOAD DATA INFILE,