1 前言javascript
因爲mysql數據庫要存儲微信暱稱,可是當微信暱稱帶有emoj表情會出現標題的錯誤。html
而後發現是emoj編碼是4個字節保存的,於mysql數據庫編碼格式utf8默認保存的是1到3個字節。java
2 解決方法node
2.1 修改數據庫編碼格式,針對mysql大於5.5版本mysql
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
修改set character_set_server,character_set_database, collation_database爲utf8mb4;sql
set character_set_server=utf8mb4;...
詳情見參考[1]數據庫
2.2 直接過濾掉emoj表情微信
3 參考server
[1] https://www.jianshu.com/p/980b243fa2c3
[2] ER_TRUNCATED_WRONG_VALUE_FOR_FIELD on saving some strings to mysql