DB / MySQL / 1045
CRITICAL

MySQL Access Denied

A client authentication failure where the MySQL server rejects the connection attempt due to invalid credentials or insufficient privileges.

Common Causes

  • Incorrect username or password provided in the connection string.
  • The user exists but is not allowed to connect from the client's specific host (e.g., 'user'@'localhost' vs. 'user'@'%').
  • The user account has been deleted or its privileges revoked.

How to Fix

1 Verify and Reset Password

If you know the correct username and host, reset the user's password directly on the MySQL server.

BASH
$ mysql> ALTER USER 'username'@'localhost' IDENTIFIED BY 'NewStrongPassword!';

2 Check User Privileges and Host

Examine the exact user accounts and their permitted hosts to ensure your connection matches.

BASH
$ mysql> SELECT user, host FROM mysql.user;

3 Create a New User (If Needed)

If the user doesn't exist or you need access from a different network, create a new user with appropriate privileges.

BASH
$ mysql> CREATE USER 'newuser'@'%' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'newuser'@'%'; mysql> FLUSH PRIVILEGES;