How to export csv from mysql utf8

I want to export csv directly from mysql using command

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

This work fine, but encoding is not utf8.How to make content exported with utf8 encoding?

+6
source share
1 answer

As described in SELECT ... INTO Syntax :

SELECT ... INTO OUTFILE is a complement to LOAD DATA INFILE . Column values ​​are converted to the character set specified in the CHARACTER SET clause. If there is no such sentence, the values ​​are reset using the binary character set. Essentially, character set conversion does not exist. If the result set contains columns in multiple character sets, the output file will also be, and you may not be able to load the file correctly.

The grammar is described in SELECT Syntax :

  [INTO OUTFILE ' file_name ' [CHARACTER SET charset_name ] 

In this way:

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

Source: https://habr.com/ru/post/953305/


All Articles