Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Workbench Connection Encoding

While testing some code I stumbled on the following MySQL error:

Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and ( utf8mb4_general_ci,COERCIBLE) for operation '='

I was using a WHERE statement on a standard MySQL UTF-8 collation column which contained a character using 4 bytes. Unless I misunderstood, while reading, I found the following information:

  • MySQL's original UTF-8 implementation was incomplete (supporting maximum 3 bytes)
  • The way to solve this is a new collation called utf8mb4 which by no means a new encoding but only used by MySQL to patch their original mistake.

On my end I see no reasons to use the original MySQL UTF-8 implementation since it's incomplete. So I did a few server side configuration to make sure all defaults were pointing to utf8mb4. Everything seemed fine but now on my application: I can use 🐼 characters in my form without having to worry about MySQL.

My problem now remains that when I connect with MySQL Workbench, it seems that the encoding is being forced to UTF-8. So even if my application works correctly, if I want to run tests directly in MySQL Workbench, I get the "Illegal mix of collation" error unless I run this fix (in Workbench) after starting the application:

SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'

I found this old question (MySQL Workbench charset) where it seemed impossible to overwrite the setting but even after I spent too much time searching for the config, I cannot believe this is still the case??

like image 482
Nicolas Bouvrette Avatar asked Sep 20 '15 23:09

Nicolas Bouvrette


1 Answers

For now, I'm afraid, you will have to live with that. There's a WL for MySQL to rename that encoding to utf8 (throwing out the existing 3 byte variant). So it makes sense to keep utf8 in MySQL Workbench or we have to use different settings for different servers, which makes things more complicated.

like image 146
Mike Lischke Avatar answered Sep 19 '22 16:09

Mike Lischke