How to Fix MySQL Error 3123 (ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR)
You get mysql error 3123 when a query has a broken optimizer hint comment. Fix it by checking the hint spelling, table names, and brackets inside the comment. MySQL maps this issue to symbol ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR under SQLSTATE HY000. The engine returns the message Optimizer hint syntax error as a warning. Your query still runs, but the database ignores the broken hint. This silent fallback can cause slow queries and high load on your servers. Root causes of mysql error 3123 in
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 get mysql error 3123 when a query has a broken optimizer hint comment. Fix it by checking the hint spelling, table names, and brackets inside the comment.
MySQL maps this issue to symbol ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR under SQLSTATE HY000. The engine returns the message Optimizer hint syntax error as a warning. Your query still runs, but the database ignores the broken hint. This silent fallback can cause slow queries and high load on your servers.
Root causes of mysql error 3123 in queries
Optimizer hints tell the database engine how to build a query execution plan. Teams place these hints inside special comment blocks right after the main query word. If a single letter or space is wrong, the parser throws warning code 3123.
Simple typos in the hint name cause most of these warnings in production. Developers might write an index hint or join hint with the wrong word. Missing parentheses around table names or index names also break the parser rules. Sometimes an app build tool strips out characters or alters comment blocks before sending queries.
Query builders and object relational mappers can also cause this warning to appear. When an app joins many tables, it may change table aliases on the fly. If the hint still uses the old table name, the syntax check fails. Database version upgrades can also drop support for old hint names and trigger warnings.
How to find and fix the warning in production
Start by capturing the exact query text that triggers the warning in your logs. Do not grant full admin rights to developers just to check live server logs. Instead, use a read role that lets your team view query warnings safely.
Read the warning message output right after you run the slow query in test. The message points to the exact text part where the hint parser failed. Compare your hint word against the official manual for your exact database version. Check that every open bracket has a matching close bracket in the comment block.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Make sure the hint sits right after the main command word like select or update. If you put a regular comment before the hint block, the parser stops reading hints. Check that all table aliases in the hint match the aliases in the query. Remove any extra commas between table names or index names inside the brackets.
Preventing hint errors in your deployment pipeline
Bad hints often slip into production because the query still returns the right rows. Your app tests pass because they only check the data, not the database warnings. You can stop this by checking for SQLSTATE HY000 warnings during your test runs.
Set up your test runner to fail if the database returns code 3123. Ask your team to review any query that uses manual optimizer hints before merging. Keep a short list of approved hints in your team docs for quick checks. When you mask sensitive data like emails or phone numbers in test results, masking rewrites matched fields in results while keeping the query structure intact for hint testing.
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 mysql error 3123 stop my query from running?
No, the database treats code 3123 as a warning rather than a hard stop. The engine ignores the broken hint and runs the query with its default plan.
Why does my query run slow when this warning appears?
When the parser sees a syntax error, it drops the hint you wrote. The optimizer then picks a slower index or join order for your query.
Can a database upgrade cause ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR?
Yes, newer database versions sometimes remove or rename old optimizer hints. Test your queries against the new version before you upgrade your live servers.
Related guides
In this post