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

标签 java mysql utf-8 mysql-workbench

我从 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/

相关文章:

ruby - UTF-8 中的无效字节序列 (ArgumentError)

java - Play 2 框架 : scala iterate through fields of java objects in view

java - Tomcat 没有在 Eclipse 中关闭

php - 如何使用 Laravel Eloquent 查询获取一张表中一行的两列

php - Laravel 5 Eloquent 只得到必要的结果

mysql - 当我将数据添加到另一个字段时增加mysql字段

java - 线程本地删除方法

java - 如何使用 RestAssured post 方法上传多张图片

python - python中\n和\r\n的区别

exception - CSipSimple 抛出异常 JNI 在应用程序中检测到错误,输入无效修改后的 UTF-8 : illegal start byte 0x8e