用腳本把csv文件導(dǎo)入mysql
1、windows做的csv文件默認(rèn)是gbk字符集,而mysql設(shè)置了默認(rèn)是utf8字符集,所以要把文件轉(zhuǎn)為utf8格式。
iconv -f GBK -t UTF8 /tmp/文件名.csv -o /tmp/文件名2.csv
2、用sql命令導(dǎo)入
load data infile '/tmp/mailut2.csv' into table db1.d fields terminated by ',' lines terminated by '\n' ignore 1 lines (id,email,passwords,name,address,dept,mobile);
ignore 1 lines 是忽略第1行,第1行是標(biāo)題行
(id,email,passwords,name,address,dept,mobile) 這里是指按這個字段順序?qū)?,即csv文件的***列導(dǎo)入到表中的id字段,第二列導(dǎo)入email字段......
如果csv文件后面還有列,則忽略。