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 表中
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
