數(shù)據(jù)庫支持emjoy表情
對于emjoy表情,插入數(shù)據(jù)庫的時候總是報錯如下:
Incorrect string value: '\xF0\x9F\x98\x8D' for column 'REAL_NAME' at row 1
從上面看出該字段不支持emjoy表情
check
查找發(fā)現(xiàn)emjoy表情采用的是utf8mb4存儲,utf8mb4是utf8的超集(包含了一些非常見字符,比如說emoji表情還有一些特殊漢字),實際上mysql里面的utf8mb4才是傳統(tǒng)意義上的utf8;性能上沒有區(qū)別,只是少數(shù)的字符用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命令就可以