简体   繁体   English

utf8mb4 处的 MySQL 5.7 character_set_client 堆栈

[英]MySQL 5.7 character_set_client stack at utf8mb4

Long story short: we have a PHP-based self-developed CMS, originally on PHP5.x and MySQL, using a healthy combination of utf8 and iso-8859-1 char-sets (don't judge, I know it's weird but it's working).长话短说:我们有一个基于 PHP 的自主开发的 CMS,最初是在 PHP5.x 和 MySQL 上,使用 utf8 和 iso-8859-1 字符集的健康组合(不要判断,我知道这很奇怪,但它是在职的)。 On our production environment our server provider upgraded to PHP7.2 and (after a few weeks of refactoring) everything works just fine.在我们的生产环境中,我们的服务器提供商升级到 PHP7.2 并且(经过几周的重构)一切正常。

Parallel to this production environment I've set up (or at least I tried to) a test environment for our development, VirtualBox Ubuntu 20.04, apache2.4, PHP7.2 and MySQL5.7.与此生产环境并行,我为我们的开发设置了(或至少我尝试过)一个测试环境,VirtualBox Ubuntu 20.04、apache2.4、PHP7.2 和 MySQL5.7。

in /etc/php/7.2/apache2/php.ini I have:/etc/php/7.2/apache2/php.ini我有:

default_charset = "iso-8859-1"

in /etc/mysql/my.cnf I have:/etc/mysql/my.cnf我有:

[client]
default-character-set   = utf8


[mysqld_safe]
default-character-set   = utf8

[mysql]
default-character-set   = utf8


[mysqld]
init_connect                   = 'SET NAMES utf8'
character-set-client-handshake = false #force encoding to uft8
character-set-server           = utf8
collation-server               = utf8_unicode_ci

Now, on our development server the character_set_client=utf8mb4 and character_set_results=utf8mb4 and I can't find a way to change it.现在,在我们的开发服务器上character_set_client=utf8mb4character_set_results=utf8mb4我找不到改变它的方法。

The problem is, that when I try to import on our development server dumps from our production server (through our CMS), or when I try to save texts with special characters like ü or ä it always cuts the word at the occurrence and saves only the rest, eg instead of chüd will save only ch or instead of einträge it saves only eintr .问题是,当我尝试从我们的生产服务器(通过我们的 CMS)导入我们的开发服务器转储时,或者当我尝试使用特殊字符(如üä)保存文本时,它总是在出现时剪切单词并仅保存其余的,例如代替chüd将只保存ch或代替einträge它只保存eintr

However I can save ü manually in DB without a problem (don't have to use ü )但是我可以在数据库中手动保存ü没有问题(不必使用ü

(we have a second development server, Ubuntu 14.04, apache2.4, PHP5.6, MySQL5.7 and basically the same settings as on PHP7.2 testserver, and everything works fine) (我们有第二个开发服务器,Ubuntu 14.04、apache2.4、PHP5.6、MySQL5.7 和 PHP7.2 测试服务器上的设置基本相同,一切正常)

Maybe PHP7.2 is doing the mess here, I am really out of ideas.也许PHP7.2在这里做的一团糟,我真的没有想法。

Any help will be appreciated.任何帮助将不胜感激。 Thank you谢谢

See "truncation" in Trouble with UTF-8 characters;请参阅UTF-8 字符问题中的“截断” what I see is not what I stored 我看到的不是我存储的

I wonder if having apache not set to UTF-8 messes up <form>s .我想知道 apache 没有设置为 UTF-8 是否会弄乱<form>s

init_connect = 'SET NAMES utf8' sets 3 CHARACTER_SET_% values if you are not connecting as "root" . init_connect = 'SET NAMES utf8'设置 3 个CHARACTER_SET_%值,如果您不是以“root”身份连接 So, change it to utf8mb4 and do not connect as "root".因此,将其更改为utf8mb4并且不要以“root”身份连接。

Are you sure about the encoding in the imported data?您确定导入数据中的编码吗? (I suspect this causes the truncation problem.) Can you get a hex dump of a small portion of the data. (我怀疑这会导致截断问题。)你能得到一小部分数据的十六进制转储吗?

For Western European languages, MySQL's utf8 and utf8mb4 work the same.对于西欧语言,MySQL 的utf8utf8mb4工作方式相同。 That is, the init_connect that you have should be adequate _if the incoming data is really UTF-8, not iso...也就是说,您拥有的init_connect应该足够了 _如果传入的数据确实是 UTF-8,而不是 iso...

For reference here are hex values:参考这里是十六进制值:

char latin1 utf8
ä    E4     C3A4
ü    FC     C3BC

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

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