将 utf-8 编码的文本加载到 MySQL 表中

2021-11-20 00:00:00 utf-8 encode decode 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

相关文章