mysql csv import meets charset

import xx.csv into mysq table xx


load data infile 'xx.csv'    into table xx character set utf8    fields terminated by ','  optionally enclosed by '"' escaped by '"'    lines terminated by '\r\n';


load data infile 'xx.csv'    into table xx character set utf8
Require :


1. The .csv file charset must match the table you create.

2.If the charset is set to utf8 , please note that the .csv file must save as utf8 without BOM.

3.If the data without " qoute the column value ,please use the simply import as :


load data infile 'xx.csv'    into table xx character set utf8



Export data to a .csv file , you can use the follow command:

select * from xx into outfile 'xx.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n';

this command will export the table xx to a xx.csv with the specific format you set , and you can

use the simply export as :

select * from xx into outfile 'xx.csv'

Give a try on it!!



在windows下修改编码格式为UTF-8的文档时,会在文件的开头产生<feff>的字符。是因为在Windows标准下的UTF-8编码文档,是以<feff>开头来标识的,成为BOM(Byte Order Mark,字节序标记)

Q:What is a BOM?

A: A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may be mandatory (or prohibited) in the Unicode data stream defined in that protocol.


  1. # CSV标准文档:RFC 4180  
  2. MYSQL_CSV_FORMAT="fields terminated by ',' optionally enclosed by '\"' escaped by '\"' lines terminated by '\r\n'"  
 


你可能感兴趣的:(mysql csv import meets charset)