mysql5.7 新增参数_5.7.8新增的一个很有的参数:max_execution_time

介绍5.7.8新增的一个很有的参数:max_execution_time

这个参数是控制select的时间,能有效控制在主库的慢查询情况.

如下例子:

mysql> show variables like 'max_execution_time';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| max_execution_time | 7000  |

+--------------------+-------+

1 row in set (0.00 sec)

mysql> select sleep(5);

+----------+

| sleep(5) |

+----------+

|        0 |

+----------+

1 row in set (5.00 sec)

mysql> select sleep(8);

+----------+

| sleep(8) |

+----------+

|        1 |

+----------+

1 row in set (7.00 sec)

mysql> select count(*) from t2 where tatus ='wudagewfsldfs';

+----------+

| count(*) |

+----------+

| 12582912 |

+----------+

1 row in set (5.60 sec)

mysql> set max_execution_time=3000;

Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from t2 where tatus ='wudagewfsldfs';

ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

mysql> select count(*) from t2;

+----------+

| count(*) |

+----------+

| 12582933 |

+----------+

1 row in set (2.03 sec)

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> update t2 set tatus='12dwsd' where id =623990;

Query OK, 1 row affected (0.29 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql> select count(*) from t2 where tatus ='wudagewfsldfs';

ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

mysql> commit;

Query OK, 0 rows affected (0.07 sec)

mysql> select count(*) from t2 where tatus ='wudagewfsldfs' for update;

ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

设置了超时时间为7s(max_execution_time参数的单位是ms),如果在这个时间范围内,就返回正确的查询结果,如果超过这个时间,整个select也就只执行7s,超过7s,就终止了该查询

后面又设置为3s,得到同样的结果;

这个参数在控制业务高峰期或者读写都在一台实例上的慢查询,可以将时间设置为2s,超过2s直接让他终止.

不过,要结合实际业务来控制,别让业务执行不下去了..

select /*+ max_execution_time(3000)*/ count(*) from t2 where tatus='wudagewfsldfs';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值