Resolving MySQL Error 1045: User Access Denied

Published December 22, 2023

Access Denied errors often occur when the server believes you do not have permission to perform a certain action. One instance where this can happen is when logging into the MySQL server.

In this guide, we will show you how to resolve MySQL Error 1045 and regain access to your database files. The most common reasons for being denied access to your MySQL database through platforms like WordPress or Magento are incorrect passwords and insufficient permissions.

When connecting to the SQL server through a programming language or command line, you may encounter MySQL error code 1045. To address this, make sure you enter the correct username and password without any typos, double-check user permissions, and verify the port.

This guide will help you understand the specific error and provide four different solutions to fix it.

MySQL error

Understanding MySQL Error 1045

MySQL is one of the most popular Database Management Systems. For example, the content on the WordPress website is manageable with MySQL. So, one of the errors that admins might face while trying to access the MySQL database through WordPress is the MySQL error 1045 windows like the following:

error 1045 (28000): Access denied for user ‘root’@

Key Causes of MySQL Error 1045: Access Denied

Before proposing solutions to resolve a problem, it’s advisable to thoroughly investigate the root causes to prevent the system from encountering such issues.

Here are the causes of MySQL Error 1045 (28000) “Access Denied for User ‘root’@’localhost’:”

  • Wrong Username & Password:  The most frequent cause of the error is because of the incorrect login credentials. When connecting to the database, users could provide the incorrect username and password. SQL Server is therefore unable to determine whether the account is authentic.
  • Accessing from the Wrong Host: To improve security, MySQL employs host-based access controls for users. Stated differently, MySQL restricts user access to hosts listed in the MySQL user database. Therefore, the error will be displayed upon any attempt to access this user table from distant machines whose hostnames are not defined. Anyway, you can use the update user set host='hostname' where user='username'; command to add a host in the MySQL user table.
  •  The user doesn’t exist: When a user tries to access a database that doesn’t exist/registered on the MySQL server, they get the error.
  •  Connected Anonymous Users:  This error also appears for website owners when users of MySQL are anonymous. The MySQL server sorts through the rows in the user table when a client tries to connect to the database. The first row that precisely matches the hostname and login is used by the server. Thus, while connecting from localhost, the anonymous user (”@localhost) comes before any other users, such as ‘user’@localhost. Using the delete from user where User = ' '; command would be helpful to remove the anonymous user from MySQL.
  • Insufficient Privileges: If you do not possess the required permissions, you will not be allowed to access the MySQL database.
  • Bash interference: Bash can change special characters in a password. To prevent this, you can, however, enclose the password in single quotations.
  • Lack of SSL: A Secure Sockets Layer (SSL) may be needed to access the database, however, it’s possible that you don’t have a working SSL certificate.

Solution 1. Check the Login Credentials Correctness

You undoubtedly believe that you are entering the username and password correctly, but you are wrong. This simple solution helps you to fix MySQL error 1045. Make sure the user and password are accurate on many occasions. Sometimes, even though it might seem obvious, using the wrong username and password is the root of the MySQL 1045 Error. Even a region or a major city might have an impact at times.

Moreover, confirm that the layout of your keyboard is correct. For example, let’s say your password contains the letter ñ, but your keyboard is set up so that when you write it, another letter appears; and like most, you might be typing the password incorrectly if nothing appears when it is required. Lastly, it is best to copy and paste the values; however, copy them from a clear text editor because sometimes when you copy them from another source, they will include spaces and everything.

Thankfully, you can verify this data by looking through your wp-config.php file. By opening a file manager through the control panel of your host, you can locate this file.

Finding your site’s root directory—typically designated public_html—is the first step in using this method. Next, it ought to contain the wp-config.php file:

Solution 2. Check User’s Privileges

The lack of privileges for the user “root” is one of the primary causes of the MySQL 1045 Error. So, you’ll need to find out the current state of these privileges first.

First, open your terminal and run the following command to check the user permissions:

ssh username@ipaddress

Once you are logged in, add the command below from the MySQL prompt:

mysql -uroot -p

Then, to grant all privileges, type:

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

Using phpMyAdmin to Check the User Privileges

phpMyAdmin can also be used to verify the user privileges. You will need to click on the User Accounts tab after logging into your hosting account in this case.

Using cPanel to Check the User Privileges

In cPanel servers, follow the path below to manage user privileges:

cPanel > Mysql databases > Current databases > Privileged users > Click on the database user.

Solution 3. Reset Password to Fix Error 1045(28000)

One of the methods to fix MySQL error 1045 is to reset your password. You can reset the database password to access MySQL and fix the issue if you can’t remember it:

  • First gain access to phpMyAdmin.
  • Next, click the WordPress database icon.
  • Among a list of tables with information that keeps your website functioning properly, you ought to see wp_comments and wp_posts.
  • Click on wp_users.
  • Passwords, email addresses, and usernames should be visible as a result. Locate the user listing that needs editing, then select Edit:
  • You can modify any aspect of the user account right here. When you can update the user listing, regardless of the hosting company you choose, make sure to check out the user_pass area. Here is where you may view the database’s current password:
  • Simply click on the text field, remove the existing password, and enter a new one to update the password. You can also choose MD5 from the Function dropdown box in the user_pass section. For further security, this will encrypt your password. Then, to save your new password, click the Go button at the bottom of the screen.

Solution 4. Verify the Correctness of the port MySQL is Listening to

A further expedient fix for the MySQL 1045 Error is to confirm that the server is listening on the appropriate port. However, it’s helpful to confirm that MySQL is running first.

First, run the command below to check the server status:

systemtl status MySQL

If the result says that the server is not running, use the following command to start it:

systemtl start MySQL

Now, you can confirm that MySQL is using the correct port by looking up its default port, which is 3306. Start a command prompt or terminal on the server that has MySQL installed.

To connect to the server, type:

mysql -username -password

Running the command below enables you to view the port number that the MySQL server is listening to:


Here or in the configuration file, you can modify the port parameter. To make the modifications take effect, restart the MySQL server. Then, you are finished using this method to fix MySQL error 1045.

If the issue persists, you can attempt using this MySQL command to manually reset the root password.

Password=PASSWORD (‘password’) WHERE User=’root’;

Explore More; Decoding Free VPN
Stay Connected on Meta, X, Instagram .