MySQL 归类服务器变量依赖于用户?

MySQL collation server variables user dependent?

在同一数据库的同一 MySQL 服务器上使用同一客户端 (Sequel Pro) 与不同的 SQL 用户连接会导致不同的整理服务器变量。

在 my.cnf 中,我包含了以下内容:

[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci, NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

连接用户 A 结果:

collation_connection = utf8_unicode_ci
collation_database = utf8_unicode_ci
collation_server = utf8_unicode_ci
init_connect = SET collation_connection = utf8_unicode_ci, NAMES utf8

连接用户 B 结果:

collation_database = utf8_unicode_ci
collation_server = utf8_unicode_ci
init_connect = SET collation_connection = utf8_unicode_ci, NAMES utf8

因此缺少 collation_connection 变量。 init_connect 是否可能由于某种原因被忽略/特定于用户?

因为没有设置collation_connection,所以出现Illegal mix of collations错误。

请注意,当具有 SUPER 权限的用户登录时,init_connect 不是 运行。这是一项安全功能,as documented:

The content of init_connect is not executed for users that have the SUPER privilege. This is done so that an erroneous value for init_connect does not prevent all clients from connecting.

这是为了防止将自己完全锁定在数据库之外:

For example, the value might contain a statement that has a syntax error, thus causing client connections to fail. Not executing init_connect for users that have the SUPER privilege enables them to open a connection and fix the init_connect value.

因此,这些用户在连接时不设置此变量是预期的行为。

可能原因:init_connect字符串似乎有误。尝试:

init_connect='SET collation_connection = utf8_unicode_ci; SET NAMES utf8;'

然后重新启动 mysql 服务。

然而,这并不能解释具有 SUPER 权限的奇怪行为..