ERROR database authentication_error ai_generated true

ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password: YES)

ID: database/mysql-access-denied

Also available as: JSON · Markdown
91%Fix Rate
93%Confidence
80Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

MySQL rejects the connection because the username/password combination is wrong, the user does not exist, or the user exists but is not allowed to connect from the client's host. MySQL's user accounts are host-specific.

generic

Workarounds

  1. 93% success Reset the user password using ALTER USER
    Connect as root: mysql -u root -p. Then run: ALTER USER 'myuser'@'localhost' IDENTIFIED BY 'newpassword'; FLUSH PRIVILEGES; If the host part is wrong, create or alter the user for the correct host: CREATE USER 'myuser'@'%' IDENTIFIED BY 'newpassword';
  2. 88% success Start MySQL in skip-grant-tables mode to recover root access
    Stop MySQL: systemctl stop mysql. Start with: mysqld_safe --skip-grant-tables &. Connect without password: mysql -u root. Reset password: FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'; Restart normally.

Dead Ends

Common approaches that don't work:

  1. Granting privileges without first creating the user or fixing the password 85% fail

    GRANT statements require the user to already exist in MySQL 8+. Running GRANT on a non-existent user fails. Even if the user exists, GRANT does not change the password.

  2. Editing the mysql.user table directly with UPDATE statements 80% fail

    Directly modifying mysql.user without running FLUSH PRIVILEGES is ineffective. Additionally, MySQL 8 uses caching_sha2_password by default, and manually editing password hashes is error-prone and insecure.

Error Chain

Leads to:
Preceded by:
Frequently confused with: