不要在MySQL中使用utf8,改用utf8mb4

mysql官網對字符集的說明:https://dev.mysql.com/doc/refman/8.0/en/charset-unicode.htmlhtml

1、爲何須要使用utf8mb4。

在mysql、MariaDB中:mysql

  • MySQL的「utf8mb4」是真正的「UTF-8」。長度是4個字節。
  • MySQL的「utf8」是mysql本身的一種「專屬的編碼」,它的最大字符長度爲 3 字節。只是「UTF-8」標準的一個子集。
    因此Emoji 表情(Emoji 是一種特殊的 Unicode 編碼,常見於 ios 和 android 手機上),和一些不經常使用的漢字,存儲就會報錯。

2、修改數據庫鏈接。參考文檔

原jdbcUrl:jdbc:mysql:///dbname?useUnicode=true&characterEncoding=UTF-8 須要去掉編碼參數useUnicode=true&characterEncoding=UTF-8 改成: jdbcUrl:jdbc:mysql:///dbnameandroid

參考文檔:
https://help.aliyun.com/knowledge_detail/41702.html
http://ju.outofmemory.cn/entry/359647
http://www.javashuo.com/article/p-smlqmjmt-kp.html
https://yq.aliyun.com/articles/674741ios

相關文章
相關標籤/搜索