How to Fix MySQL Error 3124 (ER_WARN_BAD_MAX_EXECUTION_TIME)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 3124 when a query sets an invalid timeout hint. You can fix it by removing the hint from non-read statements or using valid positive numbers. The database server returns the symbol ER_WARN_BAD_MAX_EXECUTION_TIME with SQLSTATE HY000. The message states that the execution time limit is not supported. This warning or error stops bad timeout rules from breaking your database workload. What causes mysql error 3124 in your database Database engines let you limit how long a read

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mysql error 3124 when a query sets an invalid timeout hint. You can fix it by removing the hint from non-read statements or using valid positive numbers.

The database server returns the symbol ER_WARN_BAD_MAX_EXECUTION_TIME with SQLSTATE HY000. The message states that the execution time limit is not supported. This warning or error stops bad timeout rules from breaking your database workload.

What causes mysql error 3124 in your database

Database engines let you limit how long a read query can run. Developers add optimizer hints to queries to stop slow reads from locking up resources. Still, the database engine enforces strict rules on how and where you apply this timeout hint.

First, the engine only supports query execution timeouts on read-only select statements. If an app or user puts this timeout hint inside an insert, update, or delete statement, the engine rejects it. Stored routines, triggers, and events also cannot use query-level execution time hints.

Second, the value inside the hint must be a valid positive number of milliseconds. Passing zero, a negative number, or text characters triggers the unsupported execution time message. Client drivers or ORM tools sometimes inject these bad values when a timeout setting is left blank.

Third, some database proxy layers or connection pools append hints to every outgoing statement. If the pool adds a read timeout hint to a write query, the server returns code 3124. If your session runs in strict mode, this warning can abort the whole transaction.

How to find and fix the timeout failure safely

Start by checking your app logs to find the exact query that triggered code 3124. Look at the statement type first. If the statement writes or changes data, remove the execution time hint from that query.

Mean Time to Detect (MTTD) + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, check how your app builds read queries. If an ORM or query builder adds the timeout hint, inspect the variable that feeds the timeout number. Make sure your code passes a positive integer above zero before sending the query.

If you need to stop runaway write queries, do not use optimizer hints inside the statement. Instead, set session timeouts at the database driver level or adjust server timeout settings. Avoid granting admin roles to app users just to change global timeout rules during an outage.

You should also review any middleware that rewrites queries on the fly. Update those rules so they only attach execution time hints to top-level read statements. Test the updated queries in a staging setup to confirm that warnings no longer appear.

Preventing bad timeout hints in production

Good query hygiene keeps this error out of your production logs. Train your team to use optimizer hints only on slow reporting reads. Keep standard app writes clean and free of read-only hints.

You can also add query checks to your code review steps. Reject pull requests that attach execution time hints to data modification queries or stored procedures. Centralizing how your team runs ad-hoc queries also stops manual typos from hitting production servers.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

Does error 3124 stop my query from running?

By default, code 3124 acts as a warning and the query still runs without the timeout. Still, strict error modes or client settings can turn this warning into a hard failure.

Can I use the execution time hint on update or delete queries?

No, the database engine only allows this timeout hint on read-only select statements. Using it on write queries will always trigger ER_WARN_BAD_MAX_EXECUTION_TIME.

Why do I get this error inside a stored procedure?

The database ignores query-level execution time hints inside stored procedures, functions, and triggers. You must set session or global timeout variables instead of using inline hints inside routines.

The query runs. The emails stay hidden.