How to Fix MySQL Error 3878 (ER_SECOND_PASSWORD_CANNOT_BE_EMPTY)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 3878 when you try to keep a blank password as a backup. To fix it, set a real password on the user account before you keep the old one. Database teams use dual passwords to change keys with zero downtime. This feature lets an app log in with either the old key or the new key. Still, the database engine blocks you if the current key is blank. It returns the symbol ER_SECOND_PASSWORD_CANNOT_BE_EMPTY and stops the change. Why mysql error 3878 happens in your database MySQL u

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 3878 when you try to keep a blank password as a backup. To fix it, set a real password on the user account before you keep the old one.

Database teams use dual passwords to change keys with zero downtime. This feature lets an app log in with either the old key or the new key. Still, the database engine blocks you if the current key is blank. It returns the symbol ER_SECOND_PASSWORD_CANNOT_BE_EMPTY and stops the change.

Why mysql error 3878 happens in your database

MySQL uses error code 3878 and SQLSTATE HY000 for this failure. The official message says that an empty password cannot be retained as a second password. This rule protects your system from bad security setups.

When you rotate a key, you tell the engine to keep the current password. The old key moves into the secondary slot, and the new key becomes primary. If the user had no password at all, the secondary slot would become empty. That would let anyone log in without a password during the transition window.

This problem often starts in test setups or old local databases. A developer might create a user account with a blank password for quick testing. Later, an automated script tries to rotate passwords and keep the old key active. The engine sees the blank value, blocks the command, and throws mysql error 3878.

It can also happen when a user account uses an external login plugin. Some plugins do not store a password string inside the database table. If your script tries to keep the old password for that account, the command fails.

How to diagnose and fix the password error

First, find the exact user name and host name listed in the error message. Check the system user table to see if that account has a current password hash. You will likely see an empty value in the primary credential column.

Do not work around this by keeping the account password blank. Instead, update the user account with a strong primary password right away. Do not ask the database to keep the old blank password during this first update.

Application-to-Application Password Management + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Before you run the change, check which apps use that user account to log in. Since the account had no password, those apps will need the new key right away. Update the app settings with the new key, then set the primary password in MySQL.

Once the account has a real primary password, future rotations will work as expected. On the next cycle, you can tell the engine to keep the old password. Both the primary slot and secondary slot will hold real, non-empty hashes.

How to prevent dual password failures in production

Audit your database user accounts often to find any blank passwords. No production or staging account should ever log in with an empty string. Enforce a password policy plugin so the engine rejects blank keys from day one.

Next, update your rotation scripts to check the account state before running changes. If a script spots an account with no password, it should skip the retain step. It should alert your security team and set a single strong key instead.

Finally, always drop the secondary password once your apps use the new primary key. Keeping two active passwords for too long widens your risk window. Clean up the old key as soon as the rollout finishes.

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

What does ER_SECOND_PASSWORD_CANNOT_BE_EMPTY mean?

It means you tried to save an empty password as a backup secondary password. MySQL blocks this action so accounts do not keeps the session active without a password.

Can I use a blank primary password with a real secondary password?

No, the database does not allow blank passwords in a dual password setup. Both the primary and secondary slots must hold real password values.

How do I remove a secondary password after rotation finishes?

Run an account update statement that discards the old password for that user and host. This clears the secondary slot and leaves only the new primary password active.

The query runs. The emails stay hidden.