How to Fix MySQL Error 4098 (ER_WARN_CANNOT_SECURELY_PERSIST_SENSITIVE_VARIABLES)
You get mysql error 4098 when the database saves a secret variable without encryption. You fix it by setting up a keyring component and restarting the server. MySQL lets admins save runtime settings to a local file on the disk. Some of these settings hold private data like passwords or keys. The database engine flags this state with a general warning code of HY000. It warns you that the system wrote sensitive values in plain text. What triggers mysql error 4098 in your database MySQL uses th
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 4098 when the database saves a secret variable without encryption. You fix it by setting up a keyring component and restarting the server.
MySQL lets admins save runtime settings to a local file on the disk. Some of these settings hold private data like passwords or keys. The database engine flags this state with a general warning code of HY000. It warns you that the system wrote sensitive values in plain text.
What triggers mysql error 4098 in your database
MySQL uses the symbol ER_WARN_CANNOT_SECURELY_PERSIST_SENSITIVE_VARIABLES for this specific warning message. It happens when an admin saves a sensitive system variable to disk. The engine tries to encrypt that secret value before writing the file. If the server lacks an active keyring component, encryption fails right away.
By default, the engine may fall back to writing the value without encryption. It then logs mysql error 4098 to alert your team about the risk. Anyone who can read the local disk file can see the plain value. This breaks basic security rules for production databases that hold user data.
Another cause is a broken or missing master key inside an existing keyring. The server might load the keyring component at startup, yet fail to read keys. If a disk permission rule blocks the key file, the keyring stays dark. When you persist a variable later, the server cannot lock the value.
How to diagnose the warning safely
Start by checking your server error logs and recent admin session records. Look for the exact name of the sensitive variable in the warning message. Check whether an admin or an automated script changed settings during a deploy. You do not need full root host permissions to read these database logs.
Next, check the status of the keyring component inside the database engine. Query the system performance tables to see if a keyring is active. Verify that the component shows an active status and points to valid storage. If the table returns no rows, the server ran without a keyring.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You should also check how the server handles persisted variables at startup. Review the main settings file to see if encryption is required or optional. Never turn off security warnings just to hide this message from your logs. Hiding the warning leaves plain secrets sitting on the host disk.
How to fix the issue and protect secret variables
To fix the problem, set up a supported keyring component on the host. Choose a local file keyring or an external key store that fits your setup. Make sure the operating system user for MySQL can read the keyring path. Limit file permissions so other host users cannot touch the key files.
Once the keyring manifest and config files are in place, restart the server. After the restart, check the component status tables again to confirm it works. Then re-save the sensitive system variable so the engine encrypts it on disk. The database will generate a master key and lock the sensitive values.
Finally, clean up any plain text copies of the secret in old files. Check your backup snapshots to ensure unencrypted config files do not linger there. Rotate the password or key that was saved in plain text earlier. Limit which database roles have permission to persist global system variables in production.
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
Does mysql error 4098 stop my database from running queries?
No, this code is a warning with SQLSTATE HY000, not a fatal crash. The database keeps running, but your sensitive variable sits unencrypted on the disk.
Why did the server save the variable in plain text instead of stopping?
The server settings allow unencrypted storage when a keyring component is missing. You can change the server rules to reject unencrypted sensitive variables instead.
Do I need to restart MySQL after setting up the keyring component?
Yes, the official error message recommends restarting the server with keyring component support. A restart loads the keyring early so the engine can encrypt persisted variables.
Related guides
In this post