7 ms·
Note that the encoding that MySQL calls "latin1" (and uses as its default) is not, in fact, latin1. It is windows cp1252 except with 8 random characters swapped
by lmm 9y ago
Note that the encoding that MySQL calls "latin1" (and uses as its default) is not, in fact, latin1. It is windows cp1252 except with 8 random characters swapped around. I wish I was joking.
- 0x0 9y agoHaha, and what mysql calls "utf8" is not, in fact, all of utf8. That's called "utf8mb4".
- Joeri 9y agoIt also can't sort unicode correctly according to the standard UCA algorithm. The ticket for this is closed as a wontfix.
- s_kilk 9y agoJesus Christ. Is there a reason for this? Or is it just another case of lol@mysql
- vatotemking 9y agoSo in 2017, whats the correct character set to use in MySQL?
- lmm 9y ago"utf8mb4", though really in 2017 the correct thing is to use Postgres.
- vatotemking 9y agobut not everyone can use postgres
- lmm 9y agoAnyone can if they want to enough. Some don't want it enough, or want other things more, but not using postgres is always a choice.
- Dylan16807 9y agoWhich ones? I can't find info on that.
- lmm 9y agohttps://dev.mysql.com/doc/refman/5.7/en/charset-we-sets.html https://dev.mysql.com/doc/refman/5.7/en/charset-we-sets.html Looks like I misremembered - 5 rather than 8 characters. But it isn't standard cp1252 and this can matter.
- Dylan16807 9y agoThat's just describing how it will handle erroneous data. If you give it cp1252 text, it will work exactly as expected. If you give it certain invalid characters, it will treat it as those code points.
- lmm 9y agoThere's nothing eronneous about u0081. MySQL's encoding functions are documented to behave in particular ways when a given character cannot be represented in a given encoding, and its handling of "latin1" violates that documentation unless you take into account the nonstandard extra mappings MySQL uses.
- Dylan16807 9y ago1252 does not have a character assigned to 0x81. If you store 0x81 in the database as 'latin1', then it needs to error or do something weird. If you store u0081 in the database, that's a control character in the C1 block that doesn't exist in latin1, so it needs to error or do something weird. If it violates the documentation about invalid characters, that's a problem, but that's not latin1 being incompatible with 1252.
- lmm 9y agoIf mysql handled columns declared as "ascii" as utf8 that would be "compatible" in the sense you're describing. I think it would be fair to say "mysql ascii isn't actually ascii" in that case though.