Home  >  Article  >  Database  >  Can I Control Individual Query Execution Time in MySQL?

Can I Control Individual Query Execution Time in MySQL?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-15 09:47:02789browse

Can I Control Individual Query Execution Time in MySQL?

Managing Query Execution Time in MySQL

Question: Is it possible to impose a limit on the execution time of queries in MySQL?

Original Answer:

Currently, MySQL lacks a built-in mechanism to set a maximum execution time for queries. However, an alternative approach is to implement a cron job that periodically scans the process list and terminates queries that exceed a specified time limit.

Update for MySQL 5.7 and Later:

For MySQL versions 5.7 and above, the optimizer hint MAX_EXECUTION_TIME can be included in SELECT queries. This allows the server to automatically terminate the query after the specified time.

Explanation:

The MAX_EXECUTION_TIME hint is a valuable feature that provides more granular control over query execution time within individual queries. However, it only applies to SELECT queries and does not enforce a server-wide timeout. If you require a more comprehensive solution that encompasses all types of queries and applies globally, the cron job approach remains a viable option.

The above is the detailed content of Can I Control Individual Query Execution Time in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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