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 ofLOAD DATA INFILE
. Column values are written converted to the character set specified in theCHARACTER SET
clause. If no such clause is present, values are dumped using thebinary
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' ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With