赞
踩
LOAD DATA LOCAL INFILE 'E:\\stocks.csv'
INTO TABLE `stock_info_tb`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
LOAD DATA LOCAL INFILE 'E:\\stocks.csv'
INTO TABLE `stock_info_tb` CHARACTER SET utf8
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
这个utf8是根据导入的csv文件编码来决定的,可以通过文本编辑器把要导入的数据修改一个自己喜欢的编码,然后这个一致就OK。
这样修改后,仍然是乱码,有些崩溃的。
表对中文是否支持运行:
SHOW FULL COLUMNS FROM `stock_info_tb`;
或
SHOW CREATE TABLE `stock_info_tb`;
结果显示:
CREATE TABLE `stock_info_tb` (
`type` varchar(10) CHARACTER SET latin1 DEFAULT NULL,
`bourse` varchar(2) CHARACTER SET latin1 DEFAULT NULL,
`stock_id` int(11) NOT NULL,
`stock_name` varchar(10) CHARACTER SET latin1 DEFAULT NULL,
PRIMARY KEY (`stock_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
发现要导入来的type,stock_name两个列为latin1字符集,修改为utf8为:
/*DDL 信息*/------------
CREATE TABLE `stock_info_tb` (
`type` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`bourse` varchar(2) CHARACTER SET latin1 DEFAULT NULL,
`stock_id` int(11) NOT NULL,
`stock_name` varchar(10) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`stock_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
LOAD DATA LOCAL INFILE 'E:\\stocks.csv'
INTO TABLE `stock_info_tb` CHARACTER SET utf8
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
喜欢这个样的结果。
【作者:happyprince, http://blog.csdn.net/ld326/article/details/78123282】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。