--- title: MySQL Character Set tags: Templates, Talk description: View the slide with "Slide Mode". --- # Character Set And Collation(字符集與排序規則)! <!-- Put the link to this slide here so people can follow --> 參考: https://dev.mysql.com/doc/refman/5.7/en/charset-collation-names.html --- ## 探討? - 字符集 排序規則 - 如何在utf8編碼下使用emoji: :cat: --- ### 字符集 排序規則. 一般規則: https://dev.mysql.com/doc/refman/5.7/en/charset-general.html 參考: https://dev.mysql.com/doc/refman/5.7/en/charset-mysql.html 例: utf8_general_ci 後綴的_ci代表意思 | Suffix | Meaning | | ------ | ------- | | _ai| Accent insensitive| |_as | Accent sensitive| | _ci| Case insensitive| | _cs| Case sensitive| | _bin| Binary| - ci 是不分大小寫的 例如 utf8mb4_unicode_ci - cs 是會區分大小寫的 例如 utf8mb4_unicode_cs - bin 會用 binary value 比對,例如 utf8mb4_bin 會區分大小寫的且也會區分 Ä 和 A 的不同 --- ### 使用emoji emoji表情是4個字節,而Mysql的utf8编码最多3個字節,所以數據插不進去。 utf8mb4兼容utf8,且比utf8能表示更多的字符。 emoji轉換器: https://www.ifreesite.com/unicode/ Full Emoji List, v12.0: https://unicode.org/emoji/charts/full-emoji-list.html --- ### utf8_general_ci vs utf8_unicode_ci 參考 :https://khiav223577.github.io/blog/2019/06/30/MySQL-%E7%B7%A8%E7%A2%BC%E6%8C%91%E9%81%B8%E8%88%87%E5%B7%AE%E7%95%B0%E6%AF%94%E8%BC%83/ | Column 1 | 排序速度 | 精準度 | | -------- | -------- | -------- | | utf8_general_ci | 勝 || | utf8_unicode_ci | | 勝 | utf8_general_ci比較一個字節和一個字節。它會進行大小寫折疊和重音剝離,但沒有2個字符的比較:在此排序規則中ij不相同ij utf8_unicode_ci遵循舊的Unicode標准進行比較。ij= ij,但是ae!=æ [參考連結 ](https://khiav223577.github.io/blog/2019/06/30/MySQL-%E7%B7%A8%E7%A2%BC%E6%8C%91%E9%81%B8%E8%88%87%E5%B7%AE%E7%95%B0%E6%AF%94%E8%BC%83/) [官網參考 ](https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html#charset-unicode-sets-general-versus-unicode) --- ### Thank you! :sheep: