Home >Database >Mysql Tutorial >How Can I Set a Maximum Execution Time for MySQL Queries?
Setting Maximum Execution Time for MySQL Queries
In PHP, the set_time_limit() function allows developers to limit the maximum execution time of scripts. However, there is no direct equivalent for setting such limits for MySQL queries.
Historically, MySQL didn't provide a way to enforce execution time limits. However, this changed with the introduction of MySQL 5.7.4.
Introducing max_execution_time
In MySQL 5.7.4, the max_execution_time variable was introduced. This variable allows you to specify the maximum execution time in milliseconds for top-level read-only SELECT statements.
To use this feature, you can add the following syntax to your SELECT statement:
SELECT /*+ MAX_EXECUTION_TIME(1000) */ --in milliseconds * FROM table;
This will set the maximum execution time for the query to 1000 milliseconds (1 second).
Note: This feature only applies to read-only SELECT statements.
Renaming to max_execution_time
In MySQL 5.7.8, the max_execution_time variable was renamed to max_execution_time for consistency.
Additional Information
The above is the detailed content of How Can I Set a Maximum Execution Time for MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!