将utf-8编码的文本加载到MySQL表中 [英] Loading utf-8 encoded text into MySQL table

查看:68
本文介绍了将utf-8编码的文本加载到MySQL表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的CSV文件,准备将其加载到MySQL表中.但是,这些数据被编码为utf-8格式,因为它们包含一些非英语字符. 我已经将表中相应列的字符集设置为utf-8.但是当我加载文件时.非英语字符变成怪异字符(当我对表行进行选择时).在将数据加载到表格中之前,是否需要对数据进行编码?如果是,我该怎么做.我正在使用Python加载数据,并使用LOAD DATA LOCAL INFILE命令. 谢谢

I have a large CSV file that I am going to load it into a MySQL table. However, these data are encoded into utf-8 format, because they include some non-english characters. I have already set the character set of the corresponding column in the table to utf-8. But when I load my file. the non-english characters turn into weird characters(when I do a select on my table rows). Do I need to encode my data before I load the into the table? if yes how Can I do this. I am using Python to load the data and using LOAD DATA LOCAL INFILE command. thanks

推荐答案

http://dev.mysql.com/doc/refman/5.1/en/load-data.html , 您可以使用LOAD DATA LOCAL INFILE的"CHARACTER SET"可选参数指定CSV文件使用的字符集

as said in http://dev.mysql.com/doc/refman/5.1/en/load-data.html, you can specify the charset used by your CSV file with the "CHARACTER SET" optional parameter of LOAD DATA LOCAL INFILE

这篇关于将utf-8编码的文本加载到MySQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆