gpt4 book ai didi

mysql - 特殊字符(西里尔文、中文)到 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-29 06:14:05 27 4
gpt4 key购买 nike

我有一个 csv 文件,其中包含一些行,我想使用 LOAD DATA INFILE MySQL 命令将其插入到 MySQL 表中。当我使用命令,并且插入准备就绪时,插入的特殊字符都乱七八糟。该文件正确存储了字符(我认为是这样,因为当我用像 EditPlus 这样的编辑器打开文件时,特殊字符都被破坏了,但是当用另一个编辑器(如 EmEditor)打开时,特殊字符显示正确),列将保存带有特殊字符的文本是 utf8_general_ci 的排序规则,它们是 varchar 列或 text 列。该表是一个 InnoDB 表,排序规则设置为 utf8_general_ci。我使用以下参数从 MariaDB 命令行运行 LOAD DATA INFILE 命令:

LOAD DATA INFILE '/path/to/csv/file' INTO TABLE tablename FIELDS TERMINATED BY '|' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';

编辑: 在使用 LOAD DATA INFILE 命令之前,我还尝试使用 SET NAMES "utf8"; 命令,但没有成功:|

最佳答案

MySQL 需要知道保存文件的编码(字符集)以便正确读取和解释它。

The server uses the character set indicated by the character_set_database system variable to interpret the information in the file. SET NAMES and the setting of character_set_client do not affect interpretation of input. If the contents of the input file use a character set that differs from the default, it is usually preferable to specify the character set of the file by using the CHARACTER SET clause. A character set of binary specifies “no conversion.”

弄清楚你的文件实际保存在什么编码中,或者从你的文本编辑器(已经正确解释字符的编辑器)中明确地以特定编码保存它,然后添加 CHARACTER SET ...LOAD DATA 语句中。有关详细信息,请参阅文档:http://dev.mysql.com/doc/refman/5.7/en/load-data.html

关于mysql - 特殊字符(西里尔文、中文)到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36838725/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com