MySQL Error 1045: Access denied for user
Access denied for user (using password: YES)
Verified against MySQL 9.0 docs (error-codes), Stack Overflow #1412284, MySQL Reference Manual · Updated April 2026
> quick_fix
The MySQL user/password combo is invalid, OR the user exists but isn't allowed to connect from your host. First confirm the credentials, then check if a user exists for the host you're connecting from.
-- Connect as root (adjust host as needed)
mysql -u root -p
-- See all users and their host permissions
SELECT user, host FROM mysql.user WHERE user = 'your_user';
-- Create a user for your specific host (or use % for any)
CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL ON your_db.* TO 'your_user'@'%';
FLUSH PRIVILEGES;What causes this error
MySQL authenticates the triple (user, password, host). Error 1045 fires if any of the three is wrong. Common gotcha: `alice@localhost` and `alice@%` are different users. If you created `alice@localhost` and try to connect from another machine, MySQL returns 1045 even with the right password.
How to fix it
- 01
step 1
Confirm the exact credentials
Re-type the password (no copy-paste — invisible characters can sneak in). Confirm the user spelling.
- 02
step 2
Check which host patterns exist for the user
Log in as root and query mysql.user. The host pattern matters — `alice@localhost` only allows connections from the server itself.
SELECT user, host FROM mysql.user WHERE user = 'alice'; - 03
step 3
Create or update the user for your connecting host
If no row matches your host, create one. Use % to allow any host (common for dev; restrict in production).
- 04
step 4
For reset passwords: use ALTER USER
Don't use UPDATE mysql.user on MySQL 8+. Use ALTER USER with the correct auth plugin.
ALTER USER 'alice'@'%' IDENTIFIED BY 'newpassword'; FLUSH PRIVILEGES;
Frequently asked questions
Why does MySQL say access denied for root with no password?
MySQL 8+ installs root with auth_socket (on Ubuntu) — you can only log in as the actual OS root via `sudo mysql`. Set a password with ALTER USER to enable standard password auth.
What does "using password: YES" mean?
It means you supplied a password but it was wrong (or the user/host didn't match). "using password: NO" means you connected with no password at all.