dokku / dokku-mariadb

a mariadb plugin for dokku
MIT License
73 stars 26 forks source link

Consider to change default character set to utf8 #67

Closed supermomonga closed 6 years ago

supermomonga commented 6 years ago

MariaDB's default character set is latin1, so we can't handle utf8 encoded data by default.

Since dokku-mariadb supports custom user configuration, basically I think we don't need to change default configurations, but I think this is a reasonable one to change.

dokku-mysql plugin already changed to use utf8 as a default character set by this Pull request (#62).

josegonzalez commented 6 years ago

Pull requests welcome.

allanlaal commented 3 years ago

PR #ab67e88 used utf8mb3 instead of utf8mb4, which does not cover the entire UTF8 range.

TLDR: utf8mb4 covers 100% of Unicode characters (including emojis, chinese, icons etc)

UTF-8 is a variable-length encoding. In the case of UTF-8, this means that storing one code point requires one to four bytes. However, MySQL's encoding called "utf8" (alias of "utf8mb3") only stores a maximum of three bytes per code point.

So the character set "utf8"/"utf8mb3" cannot store all Unicode code points: it only supports the range 0x000 to 0xFFFF, which is called the "Basic Multilingual Plane". See also Comparison of Unicode encodings.

This is what (a previous version of the same page at) the MySQL documentation has to say about it:

The character set named utf8[/utf8mb3] 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 supplemental characters:

  • For a BMP character, utf8[/utf8mb3] and utf8mb4 have identical storage characteristics: same code values, same encoding, same length.

  • For a supplementary character, utf8[/utf8mb3] cannot store the character at all, while utf8mb4 requires four bytes to store it. Since utf8[/utf8mb3] cannot store the character at all, you do not have any supplementary characters in utf8[/utf8mb3] columns and you need not worry about converting characters or losing data when upgrading utf8[/utf8mb3] data from older versions of MySQL.

So if you want your column to support storing characters lying outside the BMP (and you usually want to), such as emoji, use "utf8mb4". See also https://stackoverflow.com/questions/5567249/what-are-the-most-common-non-bmp-unicode-characters-in-actual-use.

source: https://stackoverflow.com/a/30074553/934511

josegonzalez commented 3 years ago

@allanlaal mind making a pr to change to the correct one?

allanlaal commented 3 years ago

PR done :)

josegonzalez commented 3 years ago

I think you did it to your repo and not this one :D

allanlaal commented 3 years ago

correct PR done. thats what happens if I dont get my mornin' coffee =)