如何为不同的用户帐户更改 MySQL session 全局变量(即 SQL_mode、max_allowed_packet 等)。我有两个用户 sam@localhost 和 joe@localhost 我需要为两个用户设置不同的 MySQL session 变量值或者需要在用户登录时更新变量值这可能吗??
最佳答案
您不能更改每个用户的 GLOBAL
值。任何 GLOBAL
选项一次只能有一个值。如果两个用户同时登录怎么办?
参见 http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html :
To change the SQL mode at runtime, set the global or session sql_mode system variable using a SET statement:
SET GLOBAL sql_mode = 'modes'; SET SESSION sql_mode = 'modes';
Setting the
GLOBAL
variable requires theSUPER
privilege and affects the operation of all clients that connect from that time on. Setting theSESSION
variable affects only the current client. Each client can change its sessionsql_mode
value at any time.
您不能更改每个 session 的服务器端 max_allowed_packet
值。每个 session 都继承自全局值。自 MySQL 5.1.31 以来, session 值是只读的。参见 https://bugs.mysql.com/bug.php?id=22891
因此,您应该将服务器端的 max_allowed_packet
值设置为任何用户所需的更大值。
您可以为 max_allowed_packet 设置客户端值,因为有效限制是服务器端值和客户端值较小。
http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_allowed_packet说:
When you change the message buffer size by changing the value of the max_allowed_packet variable, you should also change the buffer size on the client side if your client program permits it. The default max_allowed_packet value built in to the client library is 1GB, but individual client programs might override this. For example, mysql and mysqldump have defaults of 16MB and 24MB, respectively. They also enable you to change the client-side value by setting max_allowed_packet on the command line or in an option file.
您没有说明您的应用使用的客户端语言。根据语言和连接器的不同,可能无法将 max_allowed_packet 指定为客户端选项。
关于mysql - 根据不同用户账户更新MySQL全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39455082/