12

MySQL 5.6 配置

我已/etc/mysql/my.cnf手动配置为使用utf8. 见下文:

[mysqld]
character-set-server=utf8
character-sets-dir=/usr/share/mysql/charsets

[mysql]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqladmin]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlcheck]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqldump]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlimport]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlshow]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[client]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

从控制台:

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

应用程序配置

现在对于网络应用程序,我在 Tomcat 中使用了这两个连接 urlcontext.xml

url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"

url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=utf8&connectionCollation=utf8_general_ci"

以上不起作用,并为我提供了以下应用程序。

show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

这里可能有什么问题?为什么它会utf8mb4显示utf8

4

2 回答 2

17

您可能需要处理以下问题:

MySQL 连接器/J 5.1.13 中的更改 (2010-06-24)

  • Connector/J 不支持服务器 5.5.2 和更高版本的 utf8mb4。

    Connector/J 现在自动检测配置有 Java 编码 utf-8 的服务器,或将其视为在建立连接时进行的调用中character_set_server=utf8mb4传递的 Java 编码 utf-8 。(错误 #54175)characterEncoding=...utf8mb4SET NAMES=

于 2013-08-05T13:40:41.620 回答
0

对于您的网络应用程序,请尝试characterEncoding=utf8而不是 UTF-8。这解决了我的 SonarQube 容器问题。

于 2019-07-24T07:16:55.143 回答