修改long_query_time全局变量不生效, 难道是Bug吗?

问题背景: mysql server是5.7.20版本,在mysql客户端修改long_query_time全局变量由0.01修改为1但slow log日志仍显示小于1的记录,难道set global long_query_time不起作用吗?
测试一下

root@localhost:mysql3306.sock [(none)]> show global variables like 'long_query_time';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
1 row in set (0.00 sec)

root@localhost:mysql3306.sock [(none)]> show variables like 'long_query_time';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
1 row in set (0.00 sec)

root@localhost:mysql3306.sock [(none)]> set global long_query_time=2;
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3306.sock [(none)]> show global variables like 'long_query_time';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 2.000000 |
+-----------------+----------+
1 row in set (0.00 sec)

root@localhost:mysql3306.sock [(none)]> show variables like 'long_query_time';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
1 row in set (0.01 sec)

结果显示修改long_query_time全局变量后仅全局变量变更了,但当前session的long_query_time没有变更,那原因又是什么呢?
经查官方文档https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html显示,long_query_time属于全局和会话范围的系统变量

https://dev.mysql.com/doc/refman/8.0/en/using-system-variables.html显示修改全局变量仅对新会话生效而对当前会话不起作用

再查看slow log发现修改全局变量后所谓的不生效日志记录都是同一个Id: 1041729,也就是说这个会话在修改全局变量前就已创建了,这并非是MySQL的Bug~~

如果想立即生效,那该怎么办呢? 一种办法是重启mysqld服务,另一种是kill掉Sleep和Query的连接(mysql -S /tmp/mysql3306.sock -uroot -p -e 'select concat("kill ",thd_id,";") from sys.session where command="Sleep" or command="Query";'|grep kill);值得注意的是要评估此类操作对业务影响再执行!

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇