mysql - 根据不同用户账户更新MySQL全局变量?

标签 mysql database database-administration

如何为不同的用户帐户更改 MySQL session 全局变量(即 SQL_mode、max_allowed_pa​​cket 等)。我有两个用户 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 the SUPER privilege and affects the operation of all clients that connect from that time on. Setting the SESSION variable affects only the current client. Each client can change its session sql_mode value at any time.

您不能更改每个 session 的服务器端 max_allowed_pa​​cket 值。每个 session 都继承自全局值。自 MySQL 5.1.31 以来, session 值是只读的。参见 https://bugs.mysql.com/bug.php?id=22891

因此,您应该将服务器端的 max_allowed_pa​​cket 值设置为任何用户所需的更大值。

您可以为 max_allowed_pa​​cket 设置客户端值,因为有效限制是服务器端值和客户端值较小

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_pa​​cket 指定为客户端选项。

关于mysql - 根据不同用户账户更新MySQL全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39455082/

相关文章:

php - mysql卡在内部连接查询

mysql - 从多个表中合并排序数据的有效方法

php - 触发器从多个表MySQL插入多个数据

SQL选择存在子集的所有行

MySQL errno 150 尚未解决

linux - 连接 Postgres Db : Server Certificate Does Not Match Host Name 时出错

数据库 |设备上没有剩余空间

MySQL 索引有两列,其中一列是外键

php - 1小时后执行查询

mysql - 连接表中没有行引用其连接的表中的任何行