MySQL raises ER_PASSWORD_EXPIRE_ANONYMOUS_USER when you try to set PASSWORD EXPIRE on an anonymous account, which the server prohibits for security consistency.
ER_PASSWORD_EXPIRE_ANONYMOUS_USER (error 3016, SQLSTATE HY000) occurs when you attempt to expire the password of the anonymous MySQL user. Remove anonymous accounts or target a named user to resolve the issue.
ER_PASSWORD_EXPIRE_ANONYMOUS_USER
MySQL throws error 3016 with SQLSTATE HY000 and the condition name ER_PASSWORD_EXPIRE_ANONYMOUS_USER when a PASSWORD EXPIRE command targets an anonymous account. Anonymous accounts have a blank user name (''), normally used only for limited local connections.
The server blocks password expiration for these accounts because they do not authenticate with a password string. Any attempt - via ALTER USER … PASSWORD EXPIRE or CREATE USER … PASSWORD EXPIRE - immediately fails with this error.
The primary trigger is executing ALTER USER ''@'host' PASSWORD EXPIRE or including PASSWORD EXPIRE in a CREATE USER statement for ''. MySQL versions 5.7.3 and newer enforce the restriction.
Automation scripts that bulk expire passwords may loop through mysql.user and inadvertently include the anonymous row, producing the error mid-script.
Exclude anonymous accounts from any PASSWORD EXPIRE logic or, ideally, remove the anonymous user entirely. Use a WHERE clause or an explicit user list when altering accounts.
In MySQL 5.7 and later you can safely drop the anonymous user if it is not required. This eliminates both the error and a common security risk.
During security hardening the DBA runs ALTER USER *.* PASSWORD EXPIRE. The statement expands to every row, including ''. Filter the anonymous record first.
Configuration management tools like Ansible apply CREATE USER IF NOT EXISTS ''@'localhost' IDENTIFIED BY '' PASSWORD EXPIRE. Remove PASSWORD EXPIRE or supply a real user name.
Audit the mysql.user table after installation and drop anonymous accounts. Keep production servers free of ''.
Write maintenance scripts that fetch only authenticated accounts: SELECT user, host FROM mysql.user WHERE user <> ''.
Galaxy users can embed pre-approved snippets in Collections that validate user names before altering accounts, preventing accidental inclusion of anonymous users.
ER_CANNOT_USER (1396) - arises when ALTER USER targets a nonexistent account. Verify names before execution.
ER_PASSWORD_EXPIRE_REQUIRED (1820) - indicates a login allowed only to change password. Users must issue SET PASSWORD.
ER_PASSWORD_FORMAT (1372) - appears when a supplied password string uses an invalid hash format. Provide a strong plaintext value.
Security scripts that iterate through all accounts often forget to skip the blank user, triggering the error.
Automation tools that recreate default accounts with PASSWORD EXPIRE fail instantly for ''.
Guides written for pre-5.7 servers may not account for the newer restriction, leading to unexpected failures.
Raised when attempting to alter or drop a user that does not exist.
User must change password before any other operation. Occurs on login.
Occurs when SET PASSWORD or GRANT uses an invalid password hash format.
Anonymous accounts have no password to expire. Expiration logic depends on password metadata, so MySQL rejects the request.
Yes, most production servers should not allow anonymous logins. Dropping the account improves security and prevents this error.
Galaxy Collections let you store vetted ALTER USER scripts that explicitly exclude ''. Team members can run these snippets confidently.
MariaDB currently does not implement error 3016 with the same code, but similar restrictions may apply in newer releases.