简体   繁体   English

将 mysql 5.5.62 数据库架构迁移到 mysql 8.0.27 - 偶发错误 java.sql.SQLException:字符串值不正确:列的“\\xE2\\x80\\x8B”

[英]migrating mysql 5.5.62 database schema to mysql 8.0.27 - sporadic error java.sql.SQLException: Incorrect string value: '\xE2\x80\x8B' for column

Am migrating a schema from mysql 5.5.62 to mysql 8.0.27.我正在将架构从 mysql 5.5.62 迁移到 mysql 8.0.27。

The way am doing is getting a mysqldump from 5.5.62 of the required schema and then importing the dump into mysql 8.0.27.我所做的方法是从所需架构的 5.5.62 获取 mysqldump,然后将转储导入 mysql 8.0.27。

Everything works normal with the imported data however while doing an insert from a java application in one of the table fails with the following error: java.sql.SQLException: Incorrect string value: '\\xE2\\x80\\x8B' for column使用导入的数据一切正常,但是在从一个表中的 Java 应用程序插入时失败,并显示以下错误:java.sql.SQLException:字符串值不正确:列的 '\\xE2\\x80\\x8B'

The character set in mysql8.0.27 db is as below mysql8.0.27 db中的字符集如下

mysql> show variables like 'char%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.00 sec)

The character set in mysql 5.5.62 db is as below mysql 5.5.62 db中的字符集如下

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)

the jdbc connector used in the java application which is performing the insert via hibernate is mysql-connector-java-8.0.27.jar在通过休眠执行插入的 java 应用程序中使用的 jdbc 连接器是mysql-connector-java-8.0.27.jar

Why should a user needs to play with character_sets explicitly(when migrating the data to a higher version of mysql) when the user has not done anything special while creating the schema/table in the mysql 5.5.62 server?当用户在 mysql 5.5.62 服务器中创建模式/表时没有做任何特别的事情时,为什么用户需要显式地使用字符集(将数据迁移到更高版本的 mysql 时)? Any thoughts on what is the best way to deal with issues like these?关于处理此类问题的最佳方法是什么有什么想法?

Edit on 22-Nov-2021 2021 年 11 月 22 日编辑

After several days battling with this finally i came to know that the 'culprit' was a specific text returned by the Microsoft Azure API having a character '\​' at the end.经过几天的努力,我终于知道“罪魁祸首”是 Microsoft Azure API 返回的特定文本,末尾带有一个字符“\​”。 I could notice this only when i inspected the RAW text of the response returned by the Azure API in PostMan...只有当我在 PostMan 中检查 Azure API 返回的响应的 RAW 文本时,我才能注意到这一点......

The description of this '\​' (Zero Width Space) is clearly explained here https://www.fileformat.info/info/unicode/char/200B/index.htm这个'\​'(零宽度空间)的描述在这里清楚地解释了https://www.fileformat.info/info/unicode/char/200B/index.htm

Even the UTF-8 (hex) encoding of this character is '0xE2 0x80 0x8B (e2808b)'.甚至这个字符的 UTF-8(十六进制)编码也是“0xE2 0x80 0x8B (e2808b)”。 which is exactly what is the present in the SQL exception java.sql.SQLException: Incorrect string value: '\\xE2\\x80\\x8B' for column这正是 SQL 异常java.sql.SQLException: Incorrect string value: '\\xE2\\x80\\x8B' for column 中存在的内容

So for me i dont think that i need to handle this by tweaking the database character set configurations as can simply remove this character from the response and process the text before inserting to the database.所以对我来说,我认为我不需要通过调整数据库字符集配置来处理这个问题,因为可以简单地从响应中删除这个字符并在插入到数据库之前处理文本。

However i would like to keep this post active as too much of my effort was wasted troubleshooting the issue thinking this was something with the charset configuration of the DB.但是我想让这篇文章保持活跃,因为我的太多努力都浪费在解决问题上,认为这与数据库的字符集配置有关。

Having said all this i tried to execute an insert query from MySQLWorkBench with this character into the table in mysql 5.5 and it inserted the data but with a warning 1 row(s) affected, 1 warning(s): 1366 Incorrect string value: '\\xC2\\x80' for column说了这一切之后,我尝试从 MySQLWorkBench 执行一个插入查询,将此字符插入到 mysql 5.5 的表中,它插入了数据,但出现警告 1 行受影响,1 条警告:1366 字符串值不正确:' \\xC2\\x80' 用于列
Please note there is only a warning by the db and not an error请注意,数据库仅发出警告而不是错误

When i tried to do the same insert into the mysql 8.0 (via MySQLWorkBench) an error was returned by the DB Error Code: 1366. Incorrect string value: '\\xC2\\x80' for column.当我尝试对 mysql 8.0(通过 MySQLWorkBench)执行相同的插入时,DB错误代码返回错误:1366。不正确的字符串值:列的“\\xC2\\x80”。

In a real scenario if somebody needs to persist this as is in the table column then how is he/she supposed to do this?在实际情况中,如果有人需要在表列中坚持这一点,那么他/她应该如何做到这一点? Any thoughts?有什么想法吗?

Hex E2808B is the "ZERO WIDTH SPACE" in UTF-encoding. Hex E2808B 是 UTF 编码中的“零宽度空间”。

Please provide SHOW CREATE TABLE for the table in question and indicate which column was being stored into.请为有问题的表提供SHOW CREATE TABLE并指出存储在哪个列中。

Normally, I would point you at Trouble with UTF-8 characters;通常,我会将您指向UTF-8 字符问题; what I see is not what I stored for further diagnosis andhttp://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases for how to fix whichever case you have. 我看到的不是我为进一步诊断而存储的内容也不是http://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases以了解如何修复您遇到的任何情况。

Can you show us some more context?你能告诉我们更多的背景吗? That is what characters are around those 3 hex characters.这就是这 3 个十六进制字符周围的字符。

I can't quite tell if this is a "double-encoding" case or UTF-8 text incorrectly declared to be latin1 when it was INSERTed .我不能完全告诉我们,如果这是一个“双重编码”的情况下或不正确地宣布为latin1的,当它是UTF-8文本INSERTed If you can find how the string was inserted, that might help.如果您能找到字符串的插入方式,那可能会有所帮助。

C280 smells like an incorrectly encoded Eurosign. C280闻起来像是编码错误的 Eurosign。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot and Mysql: Caused by: java.sql.SQLException: Incorrect string value: '\x96 like...' for column 'description' at row 1 - Spring Boot and Mysql : Caused by: java.sql.SQLException: Incorrect string value: '\x96 like...' for column 'description' at row 1 字符编码:java.sql.SQLException:不正确的字符串值:列的'\\ xF5fi S \\ xE1…' - Character encoding: java.sql.SQLException: Incorrect string value: '\xF5fi S\xE1…' for column 异常java.sql.SQLException:错误的字符串值:'Rins'列第1行的'\\ xF0 \\ x9F \\ x92 \\ xBC' - Exception java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\xBC' for column 'Rins' at row 1 at 拆分包含Unicode字符\\ xe2 \\ x80 \\ xa9的字符串实际上不会拆分任何内容 - Splitting a string that contains unicode characters \xe2\x80\xa9 does not actually split anything java.sql.SQLException:字符串值不正确:'\\ xF3 \\ xBE \\ x8D \\ x81' - java.sql.SQLException: Incorrect string value: '\xF3\xBE\x8D\x81' java.sql.SQLException:不正确的字符串值:'\xAC\xED\x00\x05sr...' - java.sql.SQLException: Incorrect string value: '\xAC\xED\x00\x05sr...' 不正确的字符串值:'\xF2\xB8\x80\xA0\xE6\x88...' - Incorrect string value: '\xF2\xB8\x80\xA0\xE6\x88…' 使用AES_ENCRYPT的JAVA MySQL插入失败java.sql.SQLException:字符串值不正确 - JAVA MySQL insert with AES_ENCRYPT fails java.sql.SQLException: Incorrect string value java.sql.SQLException:字符串值不正确:'\\ xF0 \\ x9F \\ x98 \\ x8F'表示第1行的'tweetcontent'列 - java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8F' for column 'tweetcontent' at row 1 为什么 MySQL 和 JPA 会发生“java.sql.SQLException: Incorrect string value...” - Why "java.sql.SQLException: Incorrect string value..." is happened with MySQL and JPA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM