首页 > 解决方案 > 设置数据库 uft8mb4 后黑色菱形和问号持续存在

问题描述

标签: javamysqljdbcpayarautf8mb4

解决方案


characterEncoding=utf-8 is incompatible with utf8mb4. Use character_set_server=utf8mb4 in your JDBC URL instead, or config.addDataSourceProperty("character_set_server", "utf8mb4");. Do not use characterEncoding at all.

From the MySQL Connection/J developer guide → Using Character Sets → Setting the Character Encoding:

… to use the 4-byte UTF-8 character set with Connector/J, configure the MySQL server with character_set_server=utf8mb4, and leave characterEncoding out of the Connector/J connection string.

And right below that:

Warning

In order to use the utf8mb4 character set for the connection, the server MUST be configured with character_set_server=utf8mb4; if that is not the case, when UTF-8 is used for characterEncoding in the connection string, it will map to the MySQL character set name utf8, which is an alias for utf8mb3.


推荐阅读