Live data from Hacker News

In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

medium.com

111–120 of 170 posts

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#111
post #14
post #11

Given that the article says that everyone should use utf8mb4, then why don't/haven't they just fixed it? Should be easy enough, and probably safe, too.

They have. It's the default in MySQL 8.

Sorry, should have bern more clear: why didn't they fix the bug in utf8 so that it is correct (and would do what utf8mb4 does now)? It's just that the obvious choice of 'utf8' has been plain wrong for a long time.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#112
post #10

> If you need a database, don’t use MySQL or MariaDB. Use PostgreSQL. This is stupid. There are pros and cons to every database. For example, MySQL allows you to set a trigger on an op, PostgreSQL requires you to write a function first.

> This is stupid.

Talk about stupid, run this query on both Mysql and Postgres:

select 0 = 'banana';

Make your own conclusion.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#113

Earlier quoted context omitted.

With utf-8 you give up any hope of O(1) string operations. With utf-16 you can get O(1) string operations at a cost of doing them on code points rather than graphemes. If greater than 95% of the strings your language/program will ever see are going to be a single code point that trade off seems worth it. I think a lot of people totally discount the enormous cost that Latin-1 users are paying for CJK (etc) support the…

Except that with utf-16 you still have to give up any hope of O(1) string operations, unless you don't care about accuracy. Only UTF-32 allows O(1) index based operations. For example, 🧐 (aka face with monocle) needs 2 UTF-16 'characters', since the UTF code point is U+1F9D0, or, in UTF-8: F0 9F A7 90. And this ignored the point that others have made about combining characters, such as ‍ woman farmer Unicode: U+1F46…

To clarify the woman farmer being 14 or 15 bytes: the example given is four different combined characters, and is additionally a "medium skin tone woman farmer".

A woman farmer requires the "woman" and "ear of rice" emoji, with a zero-width joiner character between them. To change the skin tone from the default yellow, a "medium skin tone" (type 4) modifier is added after the woman, but before the joiner.

So the sequence "U+1F469 U+1F3FD U+200D U+1F33E" represents "woman skin-tone-4 joiner ear-of-rice". And in the UTF-8 bytes, the first four bytes are "woman", the next four are "skin-tone-4", then three for "zero-width-joiner", and finally four for "ear-of-rice".

Emojipedia helpfully lists codepoints for each multi-character emoji: https://emojipedia.org/female-farmer/

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#114

I use utf8 for "normal" field like name, address, etc.. (don't want smiley as first name). And use utf8mb4 for comment for example. But I need filter/validate each inputs (and refuse when there is 4 bytes characters).

Sorry for not doing my research but, aren't there 4-byte regular characters from other languages? Is it all emojis and symbols?

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#115

Earlier quoted context omitted.

They'd kind of what happened in python 3.3. The internal representation is flexible, depending on the string contents. It may be just 1byte ASCII, or it may be utf32 if needed: https://www.python.org/dev/peps/pep-0393/

Java 11 is going to a similar model.

Does anyone know if anything similar is planned for Javascript? It kills me that String.length (and [], codePointAt and so on) are living footguns. Though as other commenters have said, the rise of emoji has at least brought attention to the bugs caused by naive use of these tools.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#116

Possibly my favourite thing about the rise of emoji is that they’re not Basic Multilingual Plane, and so stupid hacks like MySQL’s utf8 character set (I seriously don’t know why anyone ever thought it was a good idea in 2002–2004) are now obviously insufficient for full Unicode support, and enough people care about them that adoption of this basic level of Unicode is driven, and so non-English speakers are inadverten…

It's a big fucking mistake is what it is.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#117
post #111
post #14

Earlier quoted context omitted.

They have. It's the default in MySQL 8.

Sorry, should have bern more clear: why didn't they fix the bug in utf8 so that it is correct (and would do what utf8mb4 does now)? It's just that the obvious choice of 'utf8' has been plain wrong for a long time.

from the article:

>Once MySQL published this invalid character set, it could never fix it: that would force every user to rebuild every database.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#118

I use utf8 for "normal" field like name, address, etc.. (don't want smiley as first name). And use utf8mb4 for comment for example. But I need filter/validate each inputs (and refuse when there is 4 bytes characters).

There are more characters outside BMP than just emoji.

Re: In MySQL, don’t use “utf8”, use “utf8mb4” (2016)

#119
post #84

Earlier quoted context omitted.

Dangerous? How do you figure? Many people assume a DB is the only way to store data. Now that’s dangerous.

Because filesystems don't contain oddities...

All storage systems have trade offs. What else is new?
Post reply on HN