ERROR 1045 (28000): Access denied for user
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
localhostbut 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 -pIf 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 rootInside the MySQL shell, update the password:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewStrongPassword';Then restart normally:
sudo systemctl restart mysql3. 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro