Where the open source database community meets: Use code PERCONA75 and secure your spot for Percona Live.  Register

Fixing MySQL 1045 Error: Access Denied

July 5, 2019
Author
Carlos Tutte
Share this Post:

MariaDB no longer meeting your needs?

Migrate to Percona software for MySQL – an open source, production-ready, and enterprise-grade MySQL alternative.

Learn More

MySQL 1045 error Access Denied
During support work, one of the most common issues we see is: “I try to connect to MySQL and get a 1045 error,” often followed by “but I’m sure my user and password are correct.” This post outlines other common causes.

MySQL 1045 Error: Common Causes

1) Connecting to the wrong host

If no host is specified, MySQL connects to localhost by default.

Fix:

2) User does not exist

Fix: Check and create user if needed:

3) Host not allowed for user

Check client IP:

Fix:

4) Incorrect password

Fix: Reset password:

5) Special characters interpreted by Bash

Fix:

6) SSL required but not used

Fix:

More info:

7) PAM backend issues

Fix: Verify system user:

Reset password:

Emergency Access Recovery

  1. Stop MySQL
  2. Add skip-grant-tables to my.cnf
  3. Start MySQL
  4. Login as root
  5. Run FLUSH PRIVILEGES;
  6. Reset password
  7. Remove skip-grant-tables
  8. Restart MySQL

You should now be able to log in normally.

Learn more about Percona Server for MySQL

0 0 votes
Article Rating
Subscribe
Notify of
guest

18 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jonatas Cruz
Jonatas Cruz
6 years ago

Pretty useful post.
Just an observation, in case 2 the “FLUSH PRIVILEGES” is not needed.

Javier T Zon
Javier T Zon
6 years ago

Staring with “skip-grant” won’t allow to run GRANT.
Keep that in mind!

marcos.albe
Editor
6 years ago
Reply to  Javier T Zon

Hah, good catch! I guess we seldom take this route, and obviously we only use direct updates to mysql tables; Will fix that line. Thanks, Javi!

Luca Ferrari
6 years ago

Just one side note: I believe showing example run as root (I mean, the operating system user) is not good and could led people to think OS’ root and mysql one are the same.

Luca Ferrari
6 years ago
Reply to  Carlos Tutte

Sorry, in a rush I’ve expressed badly my concept. I’m not saying that using mysql ‘root’ is bad, rather that it is bad to show examples run as operating system ‘root’ account. Using at least a ‘sudo’ clearly states where it is required to use operating system root or not, i.e., when operating system privileges are required.
As far as I can tell, there is not a place in your examples where I have to execute commands like ‘root@percona’ instead of an unprivileged operating system user.
That’s my point.
Sorry for the noise.

sedwards
sedwards
6 years ago

The only example shell command above that requires sudo is ‘sudo passwd ap_user’

Ian Hughson
Ian Hughson
6 years ago

Hi,

I just want to say that I’m not a Percona Server user but this post was super useful to me anyway – many thanks!

krunal patel
6 years ago

Thank You So Much. I Was Trying To Fix it for My Collage Project.

Pablo Grisafi
Pablo Grisafi
6 years ago

While this saved my life, I think there is an error. In mariaDB v 10.1.26 I needed to write
set password for ‘user’@’%’ = PASSWORD(‘mypassword’)
to make it work, instead of
set password for ‘user’@’%’ = ‘mypassword’

Fidelis Gede
Fidelis Gede
5 years ago

Hi Carlos,
Or just add the port number to thee mySQL localhost

bhadiyadravivek972
5 years ago

Thank You So Much. I Was Trying To Fix it for My Collage Project.

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved