Skip to content

How to fix MySQL error 1045?

  • by
  • 3 min read

There are many ways to store data these days, but MySQL databases remain one of the most popular, despite newer, more efficient methods appearing in recent times. However, as easy as MySQL is, it can also be tricky with all its errors and glitches. 

In this article, we’re talking about MySQL error 1045, its causes and what you can do to fix the problem.


What causes MySQL error 1045?

There are several reasons why you might run into MySQL error 1045. Some common causes include:

  • Incorrect or missing root password
  • Incorrect login credentials for user account
  • Connecting to the wrong host
  • User account doesn’t exist
  • Client host doesn’t have the required permission to connect

Also read: Fix: WP error: Could not insert the attachment into the database


How to fix MySQL error 1045?

Here are three fixes you can try out. 

Grant file permissions to user account

One of the simplest things you can do is assign global file access permissions to the problematic user account. To do so, just run the command mentioned below with root privileges. 

GRANT FILE ON *.* TO user@localhost;

Now try accessing the database again. 


Setting the root user to use the native MySQL password

Resetting the MySQL root password will give you access to the database again with root permissions so you can also fix other problematic accounts. 

Top 10 programming languages to learn in 2019

Step 1: Type the following command to launch MySQL as root in the terminal.

sudo mysql -u root

Step 2: Once the MySQL console opens up, type the following commands one after the other pressing enter after each command. 

USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE user='root';
FLUSH PRIVIILEGES;
exit:

Step 3: Now restart the MySQL service using this command.

sudo service mysql restart

Try accessing your database again it should work just fine. 


Creating a new database user

Creating an entirely new database user and then logging in with that account can also help circumvent the problem. In the commands below, replace your_user with your username.

Top 7 IDEs and Text Editors to code Python, Java, C++, HTML and more

Step 1: Type the following command to launch MySQL as root in the terminal.

sudo mysql -u root

Step 2: Once the MySQL console opens up, type the following commands one after the other pressing enter after each command. 

CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'password_here';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'localhost';
UPDATE user SET plugin='auth_socket' WHERE User='your_user';
FLUSH PRIVILEGES;
exit;

Step 3: Now restart the MySQL service using this command.

sudo service mysql restart

Try accessing your database again it should work just fine. 

Also read: What is the difference between SQL and MySQL?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>