Using this guide, you will discover three methods of resolving this error.”
What Does This Error Mean?
The best way to understand this error is to break it down into single components. This error occurs when you attempt to login into your MySQL instance on your local machine, hence ‘localhost.’
An example is as shown:
The components of the error are as follows:
- ERROR 1045 (28000) – refers to the ERROR CODE and SQLSTATE, respectively. For example, in MySQL and MariaDB, the error code 1045 means access denied for that username with the specified password.
- The second is the message string. The error message follows the format: Access denied for user ‘%s’@’%s’ (using password: %s).
NOTE: The first %s in the error message refers to the username, while the second refers to the host.
Solution 1: Sudo Into MySQL
The first and most common method to resolve this error is to sudo into your MySQL instance and set the auth_plugin to mysql_native_password.
Open your terminal and run:
Enter the password for the account and proceed.
Next, change the auth_plugin and set a new password for the root account as shown:
Changing the authentication plugin will allow you to log in to your server.
Next, flush the privileges to update the grant tables:
Finally, exit the terminal and attempt your login:
Solution 2- Manually Edit the Configuration File
If the error persists, you may need to edit the MySQL configuration file. In most cases, it is under the name my.cnf in the /etc or /etc/mysql directories.
Locate this file in the MySQL installation folder for Windows and Mac users.
If the file does not exist, create it.
Open the file with your text editor and locate the mysqld block.
Under the [mysqld] block, add the following entry.
Close and save the file.
Next, restart the MySQL server and log in.
$ mysql -u root -p
Once logged in, flush the privileges and set a new password:
Ensure to replace the command above with a secure password.
Once completed, edit my.cnf file and remove the entry we added earlier.
Restart the MySQL server and log in with your new password.
Solution 3 – Start MySQL in Safe Mode
MySQL provides you with the mysqld_safe utility for starting the MySQL server. This utility allows us to specify safe features when starting and restarting the server for diagnosing errors.
Start by stopping the MySQL Server.
Next, start MySQL with no authentication as;
The command will start the server in the background as a job.
Once the daemon is running (with authentication disabled), open a new terminal and run:
The command above should allow you to log in without a password.
Once logged in, flush the privileges and set a new password as:
Close the session and restart MySQL.
Now log in to your server with your new password.
In this article, we covered three main methods of resolving the
We hope this tutorial helped you resolve this error.