MySQL 5.6 Configuration
I have configured /etc/mysql/my.cnf
manually to use utf8
. See below:
我已手动配置/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
From console:
从控制台:
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)
Application configuration
Now for the web-app I used both of this connection url in Tomcat's context.xml
现在对于web-app,我在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"
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/ |
+--------------------------+----------------------------+
What might be wrong here? Why it is showing utf8mb4
instead utf8
?
这可能有什么问题?为什么它显示utf8mb4而不是utf8?
1 个解决方案
#1
14
You may have to do with the following:
您可能需要执行以下操作:
Changes in MySQL Connector/J 5.1.13 (2010-06-24)
MySQL Connector / J的变化5.1.13(2010-06-24)
-
Connector/J did not support utf8mb4 for servers 5.5.2 and newer.
Connector / J不支持服务器5.5.2和更新版本的utf8mb4。
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)
Connector / J现在自动检测配置有character_set_server = utf8mb4的服务器,或者在SET NAMES =在建立连接时进行的调用中使用characterEncoding = ...作为utf8mb4处理传递的Java编码utf-8。 (缺陷#54175)
#1
14
You may have to do with the following:
您可能需要执行以下操作:
Changes in MySQL Connector/J 5.1.13 (2010-06-24)
MySQL Connector / J的变化5.1.13(2010-06-24)
-
Connector/J did not support utf8mb4 for servers 5.5.2 and newer.
Connector / J不支持服务器5.5.2和更新版本的utf8mb4。
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)
Connector / J现在自动检测配置有character_set_server = utf8mb4的服务器,或者在SET NAMES =在建立连接时进行的调用中使用characterEncoding = ...作为utf8mb4处理传递的Java编码utf-8。 (缺陷#54175)