简体   繁体   English

MySQL Workbench连接编码

[英]MySQL Workbench Connection Encoding

While testing some code I stumbled on the following MySQL error: 在测试一些代码时,我偶然发现了以下MySQL错误:

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. 我在标准MySQL UTF-8归类列上使用WHERE语句,该列包含使用4个字节的字符。 Unless I misunderstood, while reading, I found the following information: 除非我误解了,否则在阅读时会发现以下信息:

  • MySQL's original UTF-8 implementation was incomplete (supporting maximum 3 bytes) MySQL的原始UTF-8实现不完整(最多支持3个字节)
  • 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. 解决此问题的方法是一个名为utf8mb4的新排序规则,它绝不是新的编码,只能由MySQL用来修补其原始错误。

On my end I see no reasons to use the original MySQL UTF-8 implementation since it's incomplete. 在我的末端,我认为没有理由使用原始MySQL UTF-8实现,因为它不完整。 So I did a few server side configuration to make sure all defaults were pointing to utf8mb4. 所以我做了一些服务器端配置,以确保所有默认值都指向utf8mb4。 Everything seemed fine but now on my application: I can use 🐼 characters in my form without having to worry about MySQL. 一切似乎都很好,但是现在在我的应用程序上:我可以在表单中使用🐼字符,而不必担心MySQL。

My problem now remains that when I connect with MySQL Workbench, it seems that the encoding is being forced to UTF-8. 现在的问题仍然是,当我与MySQL Workbench连接时,似乎编码被强制为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: 因此,即使我的应用程序正常运行,如果我想直接在MySQL Workbench中运行测试,除非在启动应用程序后运行此修复程序(在Workbench中),否则我会收到“排序规则的非法混合”错误:

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?? 我发现了这个老问题( MySQL Workbench charset ),那里似乎无法覆盖设置,但是即使我花了太多时间搜索配置,我也不敢相信仍然如此?

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). MySQL有一个WL,可将编码重命名为utf8(丢弃现有的3字节变体)。 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. 因此将utf8保留在MySQL Workbench中是有意义的,否则我们必须对不同的服务器使用不同的设置,这会使事情变得更加复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM