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 ‘username’@’hostname’”:

An example of the MySQL 1045 Error
MySQL 1045 Error

You might see the MySQL 1045 Error when you try to access the MySQL database through WordPress. MySQL is an SQL (Structured Query Language) database system commonly used to add, access, and manage content on a WordPress website.

Other popular database systems that use SQL are PostgreSQL and SQL Server, as well as SQLite and MariaDB.

MariaDB is what you’ll find behind the WordPress sites at Kinsta, and it’s a drop-in replacement for MySQL. Everything related to “1045 Error” and MySQL also applies to MariaDB.

When you encounter this error message, it indicates that you aren’t authorized to access the database. For example, you may be using the wrong password, the 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 interpreted 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

User credentials and access privileges are maintained in the mysql system database — specifically, that database’s user and db tables. One of the main causes of the MySQL 1045 Error is that the username in your WordPress configuration doesn’t have the permissions required to access the CMS’s database in MySQL.

If you have access to MySQL on your server’s command line (either on the machine itself or via SSH), you can enforce the required permission by logging into MySQL as the root user:

mysql -u root -p

After entering this superuser’s password and logging in, you can grant all permissions likely to be used for a WordPress database by executing the GRANT command. With the username “wp-admin” and a WordPress database on “localhost” named “companydb” as examples, the command would be:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON companydb.* TO 'wp-admin'@'localhost';

At many website hosting companies, you can also check the user privileges using phpMyAdmin.

At Kinsta, you do not have “root” access to MariaDB in phpMyAdmin, but the required database access credentials for your WordPress configuration are always available in the MyKinsta dashboard.

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 (usually established when WordPress is installed).

If you can’t remember the password you created and your host uses cPanel, go to Database, and then click on MySQL.

If you’re a Kinsta customer, you can find the database credentials in MyKinsta by navigating to Sites > sitename to reach the Site Information page and then scrolling down to the Database Access section:

A screenshot of the Database access information card in MyKinsta.
Finding phpMyAdmin and Database access options in MyKinsta.

You can copy the username and password details from those fields in MyKinsta.

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.

If you have command-line access to MySQL, you can log on as the root user and update the password for the WordPress database users like this:

ALTER USER 'wp-admin'@'localhost' IDENTIFIED BY 'NewStrongPassword';

The command above would establish a new password for a user named wp-admin.

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 24 data centers and 300+ Content Delivery Network (CDN) locations – so it’s fast, secure, and scalable. Check out our plans today!

Jeremy Holcombe Kinsta

Senior Editor at Kinsta, WordPress Web Developer, and Content Writer. Outside of all things WordPress, I enjoy the beach, golf, and movies. I also have tall people problems.