不要在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

相关文章
相关标签/搜索