MySQL utf8mb4 字符集
修改 /etc/my.cnf
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4’
重启 MySQL Server、检查字符集
mysql> SHOW VARIABLES WHERE Variable_name LIKE ‘character_set_%’ OR Variable_name LIKE ‘collation%’;
+————————–+——————–+
| Variable_name | Value |
+————————–+——————–+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+————————–+——————–+
rows in set (0.00 sec)
为了应对无线互联网的机遇和挑战、避免 emoji 表情符号带来的问题、涉及无线相关的 MySQL 数据库建议都提前采用 utf8mb4 字符集。注意Mysql5.5.3以上的版本才支持。 本文描述如何让Mysql5.5.31在原来采用UTF8字符集的情况下,升级编码为UTF8MB4。
1.修改/etc/my.cnf 文件
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
2.重启Mysql服务
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
3.升级Mysql 驱动jar包
如果经过上述步骤,应用无法连接数据的话,请检查当前使用的mysql-connector-java.jar 的版本,建议升级到mysql-connector-java-5.1.21.jar。