JDBC url for MySQL configuration to use utf8 character encoding(用于 MySQL 配置的 JDBC url 使用 utf8 字符编码)
问题描述
我已经手动配置了/etc/mysql/my.cnf
以使用utf8
.见下文:
I have configured /etc/mysql/my.cnf
manually to use utf8
. See below:
[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)
应用配置
现在对于 web 应用程序,我在 Tomcat 的 context.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"
以上不起作用,并为我提供以下应用程序.
Above does not work and gives me following for the application.
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
?
推荐答案
您可能需要处理以下问题:
You may have to do with the following:
MySQL Connector/J 的变化5.1.13 (2010-06-24)
Connector/J 不支持 utf8mb4 用于服务器 5.5.2 和更新版本.
Connector/J did not support utf8mb4 for servers 5.5.2 and newer.
Connector/J 现在自动检测使用 character_set_server=utf8mb4
配置的服务器或将使用 characterEncoding=...
传递的 Java 编码 utf-8 视为 utf8mb4
中的 SET NAMES=
调用它在建立连接时进行.(错误 #54175)
Connector/J now auto-detects servers configured with character_set_server=utf8mb4
or treats the Java encoding utf-8 passed using characterEncoding=...
as utf8mb4
in the SET NAMES=
calls it makes when establishing the connection. (Bug #54175)
这篇关于用于 MySQL 配置的 JDBC url 使用 utf8 字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 MySQL 配置的 JDBC url 使用 utf8 字符编码
基础教程推荐
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01