Skip to content
ERROR 1045 (28000): Access denied for user

ERROR 1045 (28000): Access denied for user

DodaTech 2 min read

MySQL ERROR 1045 (28000) means your username, password, or host combination was rejected by the MySQL server. This fix covers resetting credentials, checking grants, and creating the right user for your connection.

What It Means

The MySQL server verified your connection attempt but refused access because the credentials provided do not match any user record in the mysql.user table. The full error includes the user and host that were rejected.

Why It Happens

  • Wrong password for the given username and host.
  • User exists but without access from the connecting host (e.g., user is defined for localhost but you are connecting remotely).
  • The MySQL user table is corrupted or cached privileges are stale.
  • The user was dropped or never created.

How to Fix It

1. Verify credentials at the command line

Connect interactively to isolate the issue:

mysql -u root -p

If you cannot connect as root, use the MySQL safe mode procedure to reset the root password.

2. Reset a forgotten password

Stop MySQL and restart without grant tables:

sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables &
mysql -u root

Inside the MySQL shell, update the password:

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewStrongPassword';

Then restart normally:

sudo systemctl restart mysql

3. Check and fix user grants

List all users and their hosts:

SELECT User, Host FROM mysql.user;

If your user is missing for the required host, create it:

CREATE USER 'myuser'@'%' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%';
FLUSH PRIVILEGES;

4. Handle caching and stale privileges

Always run FLUSH PRIVILEGES after manual edits to grant tables:

FLUSH PRIVILEGES;

FAQ

How do I find which host MySQL expects for my user?
Run SELECT User, Host FROM mysql.user; The Host column shows the allowed origin — localhost, %, or a specific IP. Match this in your connection string.
Can I skip the password check entirely in development?
Yes, but only in non-production environments. Use --skip-grant-tables as shown above, or set skip-grant-tables in my.cnf under [mysqld]. Remember to remove it afterward.
What if 'mysql' database is corrupted?
Run mysql_upgrade -u root -p to repair system tables, then restart MySQL. This rebuilds the grant tables if they are out of sync with the MySQL version.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro