MySQL: ERROR 1045 (28000): Access denied for user
Diagnose and fix MySQL access denied errors caused by wrong passwords, auth plugin mismatches, or host restrictions.
MySQL produces "ERROR 1045 (28000): Access denied for user 'user'@'host' (using password: YES)" when authentication fails due to a wrong password, incompatible authentication plugin, or host-based access restriction.
What Causes "ERROR 1045 Access denied" in MySQL
The password provided does not match the stored password hash for the specified user. On MySQL 8.0+, the default authentication plugin changed from
mysql_native_password to
caching_sha2_password. Older clients that do not support
caching_sha2_password fail with error 1045 even with the correct password.
The MySQL user account has a host restriction. A user created as
'admin'@'localhost' can only connect from the local machine. Connections from remote IPs (
'admin'@'203.0.113.50') are rejected.
How to Fix
Reset the password if forgotten — see How to reset the MySQL root password.
Switch the auth plugin for compatibility:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{YOUR_PASSWORD}';
FLUSH PRIVILEGES;- Create or modify the user with the correct host:
CREATE USER 'admin'@'%' IDENTIFIED BY '{YOUR_PASSWORD}';
GRANT ALL ON myapp.* TO 'admin'@'%';Related MySQL Errors
MySQL: ERROR 2002 Socket error— connection fails before authentication. MySQL: ERROR 2003 Can't connect— TCP connection refused.