EMAILMethods to Fix the MySQL 1045 error: Access denied

Methods to Fix the MySQL 1045 error: Access denied

Methods to Fix the MySQL 1045 error: Access denied

MySQL Error 1045 happens when you attempt to access your MySQL database via WordPress but it will deny permission. It will happen if you use the incorrect password or do not have the proper permissions.

Fortunately, there are many ways to fix MySQL 1045 errors. So, first, understand the error and check a few troubleshooting solutions to get back on track. Let’s see the methods to fix the error!

What is MySQL error 1045?

The MySQL 1045 Error can be in different forms, like “Error 1045 (28000) access denied for user root localhost.” You typically see this error when trying to access the MySQL database through WordPress, which uses MySQL to manage your site’s content.

[root@localhost ~]# mysql -u root -p

Enter password:

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

Other databases like MariaDB and SQLite also use MySQL, but you won’t encounter the 1045 error with MongoDB, which is a schema-less NoSQL database. When you see this error, it means you’re not authorized to access the database from localhost. This could be due to using the wrong credentials or having insufficient permissions.

Causes of the MySQL error 1045

Here are some reasons behind the MySQL error:

Insufficient permissions – Without the necessary WordPress Permission, you will not be able to access the MySQL database.

User doesn’t exist – If you are not a registered user on the server, you will also receive this error.

Incorrect login credentials:  This error is due to the wrong username and password. This is common when you have different hosts because it is easy to mix up your passwords.

Wrong host or port: If you do not specify a host, MySQL will try to connect to localhost. That may be your current host or post.

SSL: Secure Socket Layer (SSL) is required to access the database.

Once you have found the reason for the MySQL 1045 Error, then you can implement the correct solution to fix the error.

Methods to fix the MySQL Error 1045:

  1. Check if the user has the necessary privileges

 

One common reason for the MySQL 1045 Error is insufficient permissions for the user “root”. So first check the current status of these privileges.

  • To check the user permissions, open your terminal based on your OS – MacOS/ Command Prompt/ Powershell.
  • Connect to your server via SSH with the following command

ssh username@ipaddress

  • After login in successfully, enter the following command to the MySQL prompt

mysql -uroot -p

  • Enter the command to grant all privileges

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

Via phpMyAdmin

  1. Click on the “Open phpMyAdmin” button.
  2. Log in with your username and password to access the database.
  3. Click the “Users” link to manage your MySQL user accounts.
  4. No matter your hosting provider, find the correct user in the database and select “Edit Privileges.
  5. Now you can view a list of the user’s privileges.
  6. Select the relevant check boxes if the user does not have the required privileges.
  7. Click “Go” to apply the changes.
  8. Verify that the changes have fixed MySQL Error 1045 by accessing the database again.

 

  1. Check you’re using the correct username and password.

Even though it appears to be a simple issue, the MySQL 1045 Error can sometimes be caused by incorrect login credentials.

 

  1. Check your wp-config.php file to verify the credentials.
  2. To find the file, you can log in to your hosting control panel or connect via SFTP.
  3. Using this method, locate the root directory of your website, which is often named as public_html. Then, find the wp-config.php file inside it.
  4. Open the file and ensure that the DB_USER and DB_PASSWORD are correct. The username is root and the password is you entered during the installation.
  5. If you’ve forgotten the password: Log in to cPanel > Database > MySQL.
  6. Reset Password

If you forget the database password, you can reset it to get access to MySQL and resolve the issues.

  1. Open
  2. Click on your WordPress database, from the left sidebar. You can find a list of tables with data that will help your site to work successfully. For example, you could see wp_comments and wp_posts among others.
  3. Click on the wp_users table to view user information.
  4. Find the user account you want to change and click “Edit”.
  5. Check the user-pass section to edit the user listing. Here you can see the database’s current password.
  6. To change your password, click in the text area, delete the current password, and enter a new one.
  7. In the user_pass area > Function dropdown list > Select MD5 > Go to save your new password.

 

  1. Check that the MySQL server is listening to the correct port

Another easy fix for the MySQL 1045 Error is to check that the server is listening on the correct port.

 

  1. First, make sure MySQL is working.
  2. To check the server status, run the following command,

systemctl status mysql

  1. If the server is not running, use the following command to start it

 systemctl start mysql

  1. MySQL’s default port is 3306, so ensure it’s running on the correct port.
  2. Open a command prompt on the server where MySQL is installed.
  3. Connect to the server using the following command

mysql -username -password

  1. Enter the following command to view the port number that the MySQL server is listening to

SHOW VARIABLES LIKE ‘port’:

  1. Now, you can change the port parameter here or in the configuration file. Then restart MySQL to apply the changes.

 

Dealing with WordPress errors can be frustrating, particularly the MySQL 1045 Error, which prevents access to your database. To resolve this issue, ensure that you are using the correct credentials. It’s also important to check that you have the necessary permissions to access the database. If you believe the password is incorrect, consider resetting it. Also, make sure that the MySQL server is listening on the correct port. These steps will allow you to resolve the error and recover your access. If you need any technical help to fix the errors, don’t hesitate to reach out to us – Get Tech Support!

 

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox

 

Latest news

How to use Java generics to avoid ClassCastExceptions

void copy(List<?> src, List<?> dest, Filter filter) { for (int i = 0; i <...

9 Cloud Security Risks for Businesses and How to Address Them

9 Cloud Security Risks for Businesses and How to Address Them By WatServ October 28, 2022 Cloud computing, when managed appropriately, is...

Must read

Top 10 CIO Trends for 2019

As we get ready to close out 2018 and...

Are the cloud wars over or just getting started?

One of the biggest opportunities for enterprises large and...

You might also likeRELATED
Recommended to you