Home > Database > Mysql Tutorial > How to Limit MySQL Query Execution Time?

How to Limit MySQL Query Execution Time?

Susan Sarandon
Release: 2025-01-05 02:23:39
Original
728 people have browsed it

How to Limit MySQL Query Execution Time?

Setting Execution Time Limits for MySQL Queries

Limiting the execution time of MySQL queries can be crucial for performance and resource optimization. This guide explores how to set a maximum execution time for MySQL queries, providing a solution that is similar to the set_time_limit() function in PHP.

Solution for MySQL 5.7.4 and Later

In MySQL 5.7.4 and subsequent versions, a new feature was introduced allowing the specification of an execution time limit for read-only SELECT statements at the server level. This limit is set in milliseconds using the MAX_EXECUTION_TIME hint:

SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM table;
Copy after login

Note: This feature is only applicable to read-only SELECT statements.

Updated Variable Name

In MySQL 5.7.8, the MAX_EXECUTION_TIME variable was renamed to max_execution_time. Therefore, for MySQL 5.7.8 and later, the syntax is as follows:

SELECT /*+ max_execution_time(1000) */ * FROM table;
Copy after login

The above is the detailed content of How to Limit MySQL Query Execution Time?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template