gpt4 book ai didi

java - mysql加载文件数据字符集处理环境是否依赖?

转载 作者:行者123 更新时间:2023-11-29 05:57:01 25 4
gpt4 key购买 nike

我从 java.sql.Statement.executeUpdate(String sql) 调用 DATA INFILE 将 UTF-8 CSV 文件加载到表中。

当我使用

LOAD DATA INFILE '/var/lib/mysql-files/upload/utf8table.csv' INTO TABLE temp.utf8table CHARACTER SET utf8 FIELDS TERMINATED BY ';'  LINES TERMINATED BY '\r\n' (@vC1, @vC2) set C1=@vC1, C2=nullif(@vC2,'');

,未指定 CHARACTER SET utf8,非 ASCII 字符已损坏。
但同一个查询在Mysql Workbench 中执行时正确地导入了所有字符。
指定字符集的查询在这两种情况下都能很好地工作。导致此类行为的执行环境有何不同?

最佳答案

根据文档:

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.”

另见 sysvar_character_set_client .如果未指定,则默认为 latin1

关于java - mysql加载文件数据字符集处理环境是否依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48447216/

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