共计 1675 个字符,预计需要花费 5 分钟才能阅读完成。
mysql 存储 emoji 表情要使用 utf8mb4 字符集,这是 4 字节存储,最低支持版本为 5.5.3+,若不是,请升级到较新版本。
修改 mysql 配置文件
Window 目录:mysql/my.ini
Ubuntu16.04 目录:/etc/mysql/conf.d/mysql.cnf 配置 Client
/etc/mysql/mysql.conf.d/mysql.cnf 配置 Server
其他目录:一般在 etc/mysql/my.cnf
在 mysql 配置文件添加以下三部分内容:
[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,检查字符集
# mysql -uroot -p
# 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)
Java 链接配置
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/tgb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE
jdbc.user=root
jdbc.password=
jdbc.initialPoolSize=10
jdbc.minPoolSize=10
jdbc.maxPoolSize=50
jdbc.maxIdleTime=3600
jdbc.testConnectionOnCheckout=false
jdbc.testConnectionOnCheckin=true
jdbc.idleConnectionTestPeriod=3600
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-10/147222.htm
正文完
星哥玩云-微信公众号