How to fix ERROR 1133: Can't find matching row in user table in MySQL

MySQLINTERMEDIATEMEDIUMUpdated Dec 23, 2025· 203 views

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.

Quick fix

Fixes ERROR 1133: Can't find matching row in user table

SELECT User, Host FROM mysql.user ORDER BY User, Host;
  1. Check which users currently exist in the database
  2. Create the user if it doesn't exist
  3. If the account exists, verify the exact host specification
  4. Use idempotent commands for scripts and automation
mysql — error
SELECT User, Host FROM mysql.user ORDER BY User, Host;
ERROR 1133: Can't find matching row in user table

What this error means

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.

Typical symptoms

  • ERROR 1133 (42000) appears when running ALTER USER, SET PASSWORD, RENAME USER, or GRANT statements
  • The error message shows: "Can't find any matching row in the user table"
  • Works fine with some user@host combinations but fails for others
  • Database restore scripts or migration scripts fail at user setup steps
  • GRANT statements silently fail to create or modify users

Common causes

  1. The user account does not exist in the mysql.user table—you're trying to modify a non-existent account
  2. Host mismatch: the account exists but under a different host than specified (e.g., account is 'user'@'localhost' but you're trying to alter 'user'@'%')
  3. NO_AUTO_CREATE_USER SQL mode is enabled, preventing GRANT from auto-creating accounts
  4. Typo in username or host specification when executing the command
  5. Database corruption or incomplete migration where mysql.user table is missing rows after a restore

How to fix "ERROR 1133: Can't find matching row in user table"

1Check which users currently exist in the database

Run the following query to list all existing user@host combinations:

sql
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.

2Create the user if it doesn't exist

If the user is not in the list, create it first using CREATE USER:

sql
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.

3If the account exists, verify the exact host specification

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:

sql
ALTER USER 'app_user'@'%' IDENTIFIED BY 'newpass';  -- Wrong host

Instead, use the correct host:

sql
ALTER USER 'app_user'@'localhost' IDENTIFIED BY 'newpass';  -- Correct

Or, if you need to support multiple hosts, create a separate account:

sql
CREATE USER 'app_user'@'%' IDENTIFIED BY 'newpass';
4Use idempotent commands for scripts and automation

To avoid this error in automated scripts or migrations, use IF EXISTS and IF NOT EXISTS clauses:

sql
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.

5After database restore, check and rebuild user accounts

If you encounter this error after restoring a MySQL backup:

1. Verify the mysql.user table was restored:

sql
SELECT COUNT(*) FROM mysql.user;

2. If there are very few rows or the user is missing, manually recreate the accounts:

sql
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:

sql
FLUSH PRIVILEGES;

Note: FLUSH PRIVILEGES only reloads the in-memory grant tables. It does NOT create missing users—you must CREATE USER explicitly.

Advanced notes

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:

sql
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:

sql
RENAME USER 'old_user'@'localhost' TO 'new_user'@'localhost';  -- old_user@localhost must exist

If 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:

sql
CREATE USER 'app'@'localhost' IDENTIFIED BY 'pass1';
CREATE USER 'app'@'192.168.1.10' IDENTIFIED BY 'pass2';

Both are valid separate accounts.

Frequently asked questions

What does "ERROR 1133: Can't find matching row in user table" mean?
user system table. MySQL stores user credentials per user AND per host combination. 10'.
How do I fix "ERROR 1133: Can't find matching row in user table"?
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.
What causes "ERROR 1133: Can't find matching row in user table"?
The user account does not exist in the mysql.user table—you're trying to modify a non-existent account Host mismatch: the account exists but under a different host than specified (e.g., account is 'user'@'localhost' but you're trying to alter 'user'@'%') NO_AUTO_CREATE_USER SQL mode is enabled, preventing GRANT from auto-creating accounts
Is the "ERROR 1133: Can't find matching row in user table" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading