LOAD DATA INFILE字元編碼的問題

2021-08-25 00:16:34 字數 1265 閱讀 2671

[quote]load data infile 'c:\users\denny\desktop\testpage\xx.csv'

into table taobao_shop

character set utf8

fields terminated by ';'

enclosed by '' escaped by ''

lines terminated by '\n' starting by ''

(id, sid, cid, nick, display_name);[/quote]

想把乙個utf-8的格式化好的文字檔案匯入到資料庫中, 文字中包含中文, 對應的資料庫表也都是使用utf-8編碼,但是使用load data infile匯入到資料庫中發現中文是亂碼?首先想到的是mysql client需要使用utf-8,於是在my.cnf檔案中加入。

[quote]default-character-set=utf8[/quote]

重試發現問題依舊,然後開啟mysql query browser裡面load data infile的文件仔細閱讀, 發現有「character set 」這個引數, 第一感覺這個應該就是我想要的。

[quote]load data [low_priority | concurrent] [local] infile 'file_name'

[replace | ignore]

into table tbl_name

[character set charset_name]

[fields

[terminated by 'string']

[[optionally] enclosed by 'char']

[escaped by 'char']

][lines

[starting by 'string']

[terminated by 'string']

][ignore number lines]

[(col_name_or_user_var,...)]

[set col_name = expr,...][/quote]

於是加上character set引數, 果然ok了。

[quote]load data infile '/tmp/youku_keywords' into table youku character set utf8 fields terminated by ',';[/quote]

注意character set是utf8 而不是 utf-8.

load data infile使用詳解

基本語法 load data low priority local infile file name txt replace ignore into table tbl name fields terminated by t optionally enclosed by escaped by lin...

load data infile 中文亂碼解決

系統配置linux mysql 預設utf8 首先使用show variables like char variable name value character set client gbk character set connection gbk character set database u...

LOAD DATA INFILE使用與詳解

mysql匯入資料一般都是用insert into,那麼mysql有沒有乙個高效匯入方法呢?答案是肯定的,那就是load data infile,下面我們來詳細的講解一下相關的使用方法 基本語法 根據官方的 load data low priority concurrent local infile...