简体   繁体   中英

How export csv from mysql utf8

I want export csv directly from mysql with command

SELECT .... 
FROM ...
INTO OUTFILE '/tmp/export.csv' 
FIELDS TERMINATED BY ',' 
ESCAPED BY '\\'
LINES TERMINATED BY '\n' ;

This work perfectly, but encode not is utf8.How make the content exported utf8 encoding?

As documented under SELECT ... INTO Syntax :

SELECT ... INTO OUTFILE is the complement of LOAD DATA INFILE . Column values are written converted to the character set specified in the CHARACTER SET clause. If no such clause is present, values are dumped using the binary character set. In effect, there is no character set conversion. If a result set contains columns in several character sets, the output data file will as well and you may not be able to reload the file correctly.

The grammar is documented under SELECT Syntax :

  [INTO OUTFILE ' file_name ' [CHARACTER SET charset_name ] 

Therefore:

SELECT .... 
FROM ...
INTO OUTFILE '/tmp/export.csv'
CHARACTER SET utf8 
FIELDS TERMINATED BY ',' 
ESCAPED BY '\\'
LINES TERMINATED BY '\n' ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM