MysqlはEmoji表情を格納[なぜutf 8が格納できないのか、およびどのようにしてEmoji表情を格納できるのか]

1990 ワード

Mysqlのutf 8コードはなぜEmojiの表情を記憶できないのですか?
  • Emoji

  • まず、Emojiのコード方式を知っています.Emojiは文字を描き、絵は図形を指し、文字は図形の隠喩で、笑顔が笑い、ケーキが食べ物を表すなど、多くの表情を表すことができます.UnicodeはE 63 EからE 757に符号化される.
  • Mysql utf 8とutf 8 mb 4の違い
  • The character set named utf8 uses a maximum of three bytes per character and contains only BMP characters. As of MySQL 5.5.3, the utf8mb4 character set uses a maximum of four bytes per character supports supplementary characters: For a BMP character, utf8 and utf8mb4 have identical storage characteristics: same code values, same encoding, same length. For a supplementary character, utf8 cannot store the character at all, whereas utf8mb4 requires four bytes to store it. Because utf8 cannot store the character at all, you have no supplementary characters in utf8 columns and need not worry about converting characters or losing data when upgrading utf8 data from older versions of MySQL. 上はMysql公式サイトのutf 8 mb 4の説明ですが、要約するとutf 8の文字セットは1文字あたり最大3バイトまで使用され、BMP(Unicode基本多文種平面.Unicodeの知識については、ウィキペディアを見て、17の平面がどういう意味か理解することをお勧めします)の文字だけが含まれています.MySQL 5.5.3.3から、utf 8 mb 4文字セットは1文字あたり最大4バイトで、補足文字をサポートします.
    まとめると、Emoji対応のUnicode符号化はutf 8対応のUnicodeパケット平面内ではなく、Mysqlのutf 8でEmoji符号化フォーマット文字を直接記憶することはできない.
    MysqlにEmojiの表情をサポートさせる様々な方法
  • Mysqlの表面をutf 8_に変更mb4
        ,               。            ,          、  ;            ,              ,      。
    
  • サービス側はBase 64を使用してEmoji符号化を変換する
  • サービス側はEmoji表情に対してBase 64圧縮
  • を行う.
    String mysqlColumn = MimeUtility.encodeWord(emojiStr);
    
  • データ格納Base 64を符号化文字列逆復号
  • .
    String emojiStr = MimeUtility.decodeWord(mysqlColumn);
    
    は、このようなBase 64変換を用いる方法に対して、サービス側で符号化および復号化を行うだけでよい.
    まとめ
    私もデータベースストレージEmojiのエラーに遭遇しました.この問題を解決するために、ネット上で資料を検索するには、以下の2つの文章を提供します.MySqlがutf 8の下でなぜEmojiの表情を保存できないのか、Unicodeの基本的な知識を理解することをお勧めします.
    参考記事
  • 1.The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
  • 2.Unicode
  • 3.Emoji