How to Fix MySQL Error 1651 (ER_QUERY_CACHE_DISABLED)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1651 when a user tries to turn on the query cache while it is off at startup. You can fix this by changing the startup rule and restarting the server, or by removing the bad session call. The database engine uses the symbol ER_QUERY_CACHE_DISABLED and the state code HY000 for this fault. It stops the session command because the core memory for the cache does not exist yet. Why mysql error 1651 happens in your database MySQL sets up memory for the query cache only when the

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 1651 when a user tries to turn on the query cache while it is off at startup. You can fix this by changing the startup rule and restarting the server, or by removing the bad session call.

The database engine uses the symbol ER_QUERY_CACHE_DISABLED and the state code HY000 for this fault. It stops the session command because the core memory for the cache does not exist yet.

Why mysql error 1651 happens in your database

MySQL sets up memory for the query cache only when the server first starts up. If the startup rule keeps the query cache off, the engine skips this memory step. Later, an app or a user might try to turn the cache on for a live session. The server blocks this change and returns the error message.

The official message states that the query cache is disabled. It tells you to restart the server with query_cache_type=1 to enable it. You cannot flip this switch on the fly while the database is running. The engine needs a full restart to set aside the right memory blocks.

This issue often pops up after a team updates their server rules to boost write speed. Many teams turn off the query cache because it can slow down busy tables. Still, legacy apps or older client scripts might still send session commands that ask for the cache. When those old scripts run against the new setup, they fail right away.

How to find the root cause in production

First, check your database logs and app error logs to find which client sent the command. Look for session setup calls that run right after an app logs in. Many database drivers and frameworks send a batch of setup rules when they start a session.

Next, check the startup file on your database host. Look at how the query cache rule is set up on that node. In replica clusters, one node might have a different startup file than the main node. This split setup causes the error to show up only on certain reads.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You do not need to give wide admin rights to developers so they can check this. Let them read the current server variables through a safe read role. This lets the team verify the state without risking changes to live server settings.

How to fix the error safely

You have two safe paths to fix this fault in a live setup. The best path for modern workloads is to update the app or script. Remove the session command that tries to change the query cache state. Once the app stops asking for the disabled cache, the error goes away at once. This fix needs zero database downtime.

The second path is for legacy apps where you cannot change the code. You must update the database startup file and set query_cache_type=1 as the error message asks. After you save the rule, plan a safe window to restart the MySQL server. Test this change in a staging setup first to check for memory or lock issues.

Keep tight control over who can change startup files or run server restarts. Require peer review for any session or admin task on live nodes. Also, make sure that query logs mask sensitive fields like emails, phone numbers, card numbers, and national IDs. Masking rewrites matched fields in results so debugging stays safe.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

Can I fix mysql error 1651 without restarting the database?

Yes, if you stop the app from sending the session command that enables the cache. If you actually need the query cache turned on, you must change the startup rule and restart the server.

Why did this error start after a server change?

An admin likely turned off the query cache at startup to improve write speed. Old app scripts that still try to set the cache variable at the session level will then trigger the error.

Does this error affect data safety or table locks?

No, this error only stops the specific session command that tried to change the cache state. Your stored data remains safe, and the engine does not lock any tables when it rejects the call.

The query runs. The emails stay hidden.