本文主要是介绍myql设置utf8mb4字符,使支持emoji 表情符号,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Mysql5.5.3以上的版本才支持utf8mb4字符集。
1.修改配置文件
vi /etc/my.cnf
增加如下配置
-----------------------------------
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
-----------------------------------
2.重启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 |
+--------------------------+--------------------+
| 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 |
+--------------------------+--------------------+
3. 升级Mysql 驱动jar包
建议升级到mysql-connector-java-5.1.21.jar,或者更高版本。
处理以上方式也可以通过,设置全局参数修改,只不过这是个临时方案,但不用重启机器
如:
mysql>SET GLOBAL character_set_server= utf8mb4
......
参考文档: http://www.laruence.com/2008/01/05/12.html
这篇关于myql设置utf8mb4字符,使支持emoji 表情符号的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!