This error occurs when trying to modify (ALTER, SET PASSWORD, RENAME) a MySQL user account that doesn't exist in the mysql.user table. The fix is to create the user first or verify the exact user@host combination matches.
MySQL ERROR 1133 (ER_PASSWORD_NO_MATCH) is raised when you attempt to modify a user account using ALTER USER, SET PASSWORD, RENAME USER, or GRANT statements, but the specified user@host combination does not exist in the mysql.user system table. MySQL stores user credentials per user AND per host combination. For example, 'app_user'@'localhost' is different from 'app_user'@'%' or 'app_user'@'192.168.1.10'. If your command targets a user@host pair that doesn't exist, MySQL cannot find a row to modify and raises this error. This error is distinct from authentication failures—it's a metadata mismatch on the server side, not a password check failure.
Run the following query to list all existing user@host combinations:
SELECT User, Host FROM mysql.user ORDER BY User, Host;This shows the exact user@host rows available. Compare this list to the user you're trying to modify. Note the exact capitalization and host value.
If the user is not in the list, create it first using CREATE USER:
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'StrongP@ss!';Replace 'app_user' and 'localhost' with your actual username and host. The host can be:
- 'localhost' for local connections
- '%' for all hosts (security note: use specific IPs in production)
- A specific IP like '192.168.1.10'
After creating the user, you can then run your ALTER USER, SET PASSWORD, or GRANT statement.
If the user is in the list but your command still fails, the host mismatch is likely the cause.
For example, if the table shows 'app_user'@'localhost' but you're running:
ALTER USER 'app_user'@'%' IDENTIFIED BY 'newpass'; -- Wrong hostInstead, use the correct host:
ALTER USER 'app_user'@'localhost' IDENTIFIED BY 'newpass'; -- CorrectOr, if you need to support multiple hosts, create a separate account:
CREATE USER 'app_user'@'%' IDENTIFIED BY 'newpass';To avoid this error in automated scripts or migrations, use IF EXISTS and IF NOT EXISTS clauses:
CREATE USER IF NOT EXISTS 'dev'@'%' IDENTIFIED BY 'SecurePass123';
ALTER USER IF EXISTS 'dev'@'%' IDENTIFIED BY 'UpdatedPass456';This way, if the user doesn't exist, it's created first. If it does exist, it's updated. No error either way.
If you encounter this error after restoring a MySQL backup:
1. Verify the mysql.user table was restored:
SELECT COUNT(*) FROM mysql.user;2. If there are very few rows or the user is missing, manually recreate the accounts:
CREATE USER 'restored_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON mydb.* TO 'restored_user'@'localhost';3. Flush privileges to ensure changes take effect:
FLUSH PRIVILEGES;Note: FLUSH PRIVILEGES only reloads the in-memory grant tables. It does NOT create missing users—you must CREATE USER explicitly.
SQL Modes and NO_AUTO_CREATE_USER: In older MySQL versions, the NO_AUTO_CREATE_USER SQL mode was enabled by default. This mode prevents GRANT from automatically creating users. If your GRANT statement fails with ERROR 1133, check your SQL mode:
SELECT @@sql_mode;If NO_AUTO_CREATE_USER is present, either remove it from your configuration or use CREATE USER explicitly before GRANT.
Host Wildcards: When specifying hosts, note that:
- 'user'@'localhost' only allows Unix socket and TCP connections from localhost
- 'user'@'127.0.0.1' only allows TCP from 127.0.0.1
- 'user'@'%' allows connections from any host (use specific IPs in production for security)
RENAME USER Gotcha: The RENAME USER command has a similar behavior—it requires the source user@host to exist:
RENAME USER 'old_user'@'localhost' TO 'new_user'@'localhost'; -- old_user@localhost must existIf the source doesn't exist, you get ERROR 1133.
Connections from Different Hosts: Remember MySQL authentication is user@host-based. You can have multiple accounts with the same username but different hosts, each with different passwords or privileges:
CREATE USER 'app'@'localhost' IDENTIFIED BY 'pass1';
CREATE USER 'app'@'192.168.1.10' IDENTIFIED BY 'pass2';Both are valid separate accounts.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions