MySQL - can I limit the maximum time allowed for a query to run?(MySQL - 我可以限制允许查询运行的最长时间吗?)
问题描述
我正在寻找一种方法来限制 mysql 服务器上查询的最大运行时间.我认为这可以通过 my.cnf
配置文件完成,但在文档中找不到任何相关内容.有谁知道这是否可以做到?谢谢.
I'm looking for a way to limit the max running time of a query on mysql server. I figured this could be done through the my.cnf
configuration file, but couldn't find anything relevant in the docs. Anyone knows if this could be done? thanks.
推荐答案
更新
从 MySQL 5.7 开始,您可以包含 MAX_EXECUTION_TIME
优化器提示在 SELECT
查询中指示服务器在指定时间后终止它.
Update
As of MySQL 5.7, you can include a MAX_EXECUTION_TIME
optimizer hint in your SELECT
queries to instruct the server to terminate it after the specified time.
据我所知,如果您想强制执行服务器范围的超时,或者您关心除 SELECT
之外的查询,那么原始答案仍然是您唯一的选择.
As far as I know, if you want to enforce a server-wide timeout, or if you care about queries besides SELECT
s, the original answer is still your only option.
在向服务器发送查询以运行时,无法指定最长运行时间.
There is no way to specify a maximum run time when sending a query to the server to run.
但是,在您的数据库服务器上每秒运行一次 cron 作业并进行连接并执行以下操作的情况并不少见:
However, it is not uncommon to have a cron job that runs every second on your database server, connecting and doing something like this:
- 显示处理程序
- 查找查询时间大于所需最大时间的所有连接
- 为每个进程运行 KILL [进程 ID]
这篇关于MySQL - 我可以限制允许查询运行的最长时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL - 我可以限制允许查询运行的最长时间吗?


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01