BlackWhite
BlackWhite

Reputation: 832

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?

Upvotes: 11

Views: 30389

Answers (1)

eggyal
eggyal

Reputation: 125835

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

Upvotes: 23

Related Questions