Loading utf-8 encoded text into MySQL table(将 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 表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 utf-8 编码的文本加载到 MySQL 表中


基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01