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.
In this post, we’ll take a closer look at MySQL Error 1045 and discuss some common causes. Then, we’ll guide you through four methods to fix the error. Let’s get started!
What Is the MySQL 1045 Error?
This error comes in a number of forms, but throughout this post, we’ll refer to it as MySQL Error 1045. However, the error may also present as “Error 1045 (28000) access denied for user root localhost”:
Typically, you’ll 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.
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’ll 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:
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:
Here, click on the Open phpMyAdmin link. 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’ll need to locate the appropriate user within the database and click on Edit Privileges. Here, you’ll be able to 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’ll 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:
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’ll need to access phpMyAdmin.
Next, open the WordPress database from the left of the screen:
Here, you’ll 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:
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:
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:
systemtl status MySQL
If the server isn’t running, start it by using this command:
systemtl 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.
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!