The MySQL Error 1045 typically occurs when you attempt to access your MySQL database through WordPress. The request will be denied if the server doesn’t think you’re authorized to perform the action. For instance, you might be using the wrong password or you might not have the required permissions.

Fortunately, there are plenty of ways to fix the MySQL 1045 Error. For example, you can reset your password, check on the user permissions, and verify the port.

This post discusses some common causes of the MySQL Error 1045 and guides you through four methods to fix the it. Let’s get started!

What is the MySQL 1045 error?

This error comes in a number of forms, but throughout this post, we refer to it as MySQL Error 1045. However, the error may also present as “Error 1045 (28000) access denied for user root localhost”:

An example of the MySQL 1045 Error
MySQL 1045 Error

Typically, you see the MySQL 1045 Error when you try to access the MySQL database through WordPress. MySQL is the database system that is used to add, access, and manage content in your WordPress website.

Other popular databases that use MySQL are MariaDB and SQLite. MongoDB on the other hand is a schema less NoSQL database, so you won’t find the 1045 error when using it.

When you encounter this error message, it indicates that you aren’t authorized to access the database from localhost. For example, you may be using the wrong password, or wrong username, or have insufficient permissions.

What are the causes of the MySQL error 1045?

Here are some of the main causes of MySQL Error 1045:

  • Insufficient permissions — You won’t be granted access to the MySQL database if you don’t have the necessary WordPress permissions.
  • User doesn’t exist — You also see the error if you’re not registered as a user on the server. In this instance, the database simply doesn’t know of your existence.
  • Incorrect login credentials — The cause of the error may be something as simple as using the wrong password and username. This can often be the case if you have multiple hosts since it’s easy to mix up your passwords.
  • Wrong host — If you don’t specify the host to connect with, MySQL will attempt to connect to localhost. Meanwhile, you might be trying to connect to a different host or port.
  • Bash interference — Special characters in the password can be converted by Bash. However, you can wrap the password in single quotes to avoid this.
  • No SSL — In order to access the database, Secure Sockets Layer (SSL) may be required, but you might not have a valid SSL certificate.

Once you’ve identified the cause of the MySQL 1045 Error, you’re in a better position to apply the correct solution. Then, you can clear the error message and get back to work.

How to fix the MySQL 1045 error (4 methods)

Now that you know a bit more about MySQL Error 1045, let’s take a look at four simple methods to fix it.

1. Verify that the user has the necessary privileges

One of the main causes of the MySQL 1045 Error is that the user “root” does not have the necessary permissions. So, the first thing you’ll want to do is check the status of these privileges.

You can check the user permissions by opening your terminal and entering the following:

ssh username@ipaddress

After successfully logging in, add the following command from the MySQL prompt:

mysql -uroot -p

Then, enter this command to grant all privileges:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password';

You can also check the user privileges using phpMyAdmin. In this instance, you’ll need to log into your hosting account and click on the User Accounts tab.

If you’re a Kinsta customer, the process is a little different. Once you’ve logged into your dashboard, go to WordPress Sites and choose the site that you want to check permissions for. Then, in the Info tab, scroll down to Database access:

Open phpMyAdmin from your MyKinsta dashboard
phpMyAdmin in the MyKinsta dashboard

Here, click on the Open phpMyAdmin button. You’ll need to enter your username and password to access the database. Then, select the Users link to manage all your MySQL user accounts.

No matter what hosting provider you use, you need to locate the appropriate user within the database and click on Edit Privileges. Here, you can see a list of privileges that the user has been granted.

If the user doesn’t have the required privileges, you can grant them by selecting the relevant check boxes. Then, click on Go to apply your changes. Now, try accessing the database again to see if MySQL Error 1045 has cleared.

2. Make sure you’re using the correct username and password

Although it may seem simple, sometimes, the cause of the MySQL 1045 Error is that you’re using incorrect login credentials. Fortunately, you can check this information by consulting your wp-config.php file.

You can find this file by logging into your host’s control panel and accessing a file manager. Or, you can connect to your site via SFTP.

With this approach, you first need to locate the root directory of your site, which is usually labeled public_html. Then, you should find the wp-config.php file inside it:

Locating the wp-config.php file using an FTP client
Locate the wp-config.php file

Open the file and check that the DB_USER and DB_PASSWORD have the correct values. The username is root. Meanwhile, the password is the one you set during installation.

If you can’t remember the password you created, you can access cPanel, go to Database, and then click on MySQL. If you’re a Kinsta customer, you can check this information under Info > Database access (see the section above for further details).

3. Reset your password

If you can’t remember the password for the database, you can reset it to gain access to MySQL and clear the error. First, you need to access phpMyAdmin.

Next, open the WordPress database from the left of the screen:

View the database tables in phpMyAdmin
Database tables in phpMyAdmin

Here, you have a list of tables containing data that helps your site run smoothly. For instance, you should see wp_comments and wp_posts among others.

At this point, click on wp_users. This should reveal basic user information like usernames, email addresses, and passwords. Find the user listing that you need to change and click on Edit:

Edit a user listing in phpMyAdmin
Edit a user listing in phpMyAdmin

Here, you can change all the details of the user account.

No matter what hosting provider you use, once you’re able to edit the user listing, look out for the user_pass section. This is where you can see the current password for the database:

Reset your MySQL password
Reset your MySQL password

To change the password, click in the text area and simply delete the password and enter a new one.

In the user_pass area, you can also use the Function dropdown menu to select MD5. This will encrypt your password for extra security. Then, click on Go at the bottom of the screen to save your new password.

4. Make sure the MySQL server is listening to the correct port

Another quick solution to the MySQL 1045 Error is to make sure the server is listening to the right port. First, though, it’s useful to check that MySQL is running.

You can check the server status by running the following command:

systemctl status mysql

If the server isn’t running, start it by using this command:

systemctl start mysql

Now, the default port for MySQL is 3306 so you can make sure it’s running the correct port. Open a terminal or command prompt on the server where MySQL is installed.

Then, connect to the server using this command:

mysql -username -password

Now, type the following command to display the port number that the MySQL server is listening to:

SHOW VARIABLES LIKE ‘port’:

You can change the port parameter here or in the configuration file. Then, restart the MySQL server to apply the changes.

Summary

WordPress errors can be frustrating and hinder your ability to make important changes to your site. The MySQL 1045 Error is particularly problematic because it stops you from accessing your database. Fortunately, there are ways you can fix it.

For starters, you might need to check that you have the necessary privileges to access the database. Or, it may be a simple case of using the wrong username and password. Alternatively, you can reset your password or check that the MySQL server is listening to the right port.

At Kinsta, all of our plans offer top-quality support to help you troubleshoot issues quickly. What’s more, our database hosting has 25 data centers and 260+ Content Delivery Network (CDN) locations – so it’s fast, secure, and scalable. Check out our plans today!