字符集UTF-8MB4html
utf8mb4兼容utf8,且比utf8能表示更多的字符。
看unicode編碼區
從1 ~ 126就屬於傳統utf8區,固然utf8mb4也兼容這個區,126行如下就是utf8mb4擴充區,何時你須要存儲那些字符,你才用utf8mb4,不然只是浪費空間。mysql
官方地址:http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.htmlsql
MySQL 要存儲emoji表情,所以發現咱們經常使用的utf8 字符集根本沒法存儲表情。數據庫
首先將咱們數據庫默認字符集由utf8 更改成utf8mb4,對應的表默認字符集也更改成utf8mb4 已經存儲表情的字段默認字符集也作了相應的調整。app
SQL 語句測試
1 # 修改數據庫: 2 ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; 3 # 修改表: 4 ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 5 # 修改表字段: 6 ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
修改MySQL配置文件編碼
新增以下參數:url
1 [client] 2 default-character-set = utf8mb4 3 4 [mysql] 5 default-character-set = utf8mb4 6 7 [mysqld] 8 character-set-client-handshake = FALSE 9 character-set-server = utf8mb4 10 collation-server = utf8mb4_unicode_ci 11 init_connect='SET NAMES utf8mb4'
檢查環境變量 和測試 SQL 以下:spa
1 mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; 2 +--------------------------+--------------------+ 3 | Variable_name | Value | 4 +--------------------------+--------------------+ 5 | character_set_client | utf8mb4 | 6 | character_set_connection | utf8mb4 | 7 | character_set_database | utf8mb4 | 8 | character_set_filesystem | binary | 9 | character_set_results | utf8mb4 | 10 | character_set_server | utf8mb4 | 11 | character_set_system | utf8 | 12 | collation_connection | utf8mb4_unicode_ci | 13 | collation_database | utf8mb4_unicode_ci | 14 | collation_server | utf8mb4_unicode_ci | 15 +--------------------------+--------------------+ 16 rows in set (0.00 sec)
MySQL版本必須爲5.5.3以上版本,不然不支持字符集utf8mb4.net
測試,以下修改亦可
項目中的配置文件以下修改
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://***.***.***.***:3306/fsmp?useSSL=false
jdbc.username=***
jdbc.password=***
數據庫鏈接池配置
參考文獻:
http://blog.arkency.com/2015/05/how-to-store-emoji-in-a-rails-app-with-a-mysql-database/