gpt4 book ai didi

mysql - MySQL 配置使用 utf8 字符编码的 JDBC url

转载 作者:IT老高 更新时间:2023-10-29 00:16:06 32 4
gpt4 key购买 nike

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 的 context.xml

中使用了这两个连接 url
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

最佳答案

您可能需要处理以下内容:

Changes in MySQL Connector/J 5.1.13 (2010-06-24)

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

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

关于mysql - MySQL 配置使用 utf8 字符编码的 JDBC url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18058297/

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