mysql 數據庫支持emjoy表情

數據庫支持emjoy表情

對於emjoy表情,插入數據庫的時候總是報錯如下:

Incorrect string value: '\xF0\x9F\x98\x8D' for column 'REAL_NAME' at row 1

從上面看出該字段不支持emjoy表情

check

查找發現emjoy表情採用的是utf8mb4存儲,utf8mb4是utf8的超集(包含了一些非常見字符,比如說emoji表情還有一些特殊漢字),實際上mysql裏面的utf8mb4纔是傳統意義上的utf8;性能上沒有區別,只是少數的字符用4byte進行編碼,

官方說明:

Connector/J did not support utf8mb4 for servers 5.5.2 and newer.
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)

參考文獻:

http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-13.html

關於其它客戶端如何連接方法

Python

 self.conn=MySQLdb.connect(host="xxx",user="xxx",passwd="xxx",charset="utf8",init_command="set names utf8mb4”)

PHP

 建立連接使用set names utf8mb4命令就可以
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章