The error message you provided, “ERROR 1698 (28000): Access denied for user ‘root’@’localhost’ (using password: yes/No) MySQL,” occurs when attempting to connect to a MySQL database using the ‘root’ user account from the ‘localhost’ host, but the provided password is incorrect or does not set privileges of the ‘root’ user.
Here’s a breakdown of the error message:
ERROR 1698: This is the error code returned by MySQL.
(28000): This is the error number within the MySQL error code system. The number 28000 generally corresponds to “Access denied.”
Access denied for user 'root'@'localhost': This part of the error message indicates that the user account ‘root’ is being denied access when trying to connect from the ‘localhost’ host.
(using password: yes/No): This part of the error message indicates that MySQL is expecting a password, and it’s indicating whether the password was provided (‘yes’) or not (‘No’).
The most common reasons for this error include:
- Incorrect Password: The password you provided for the ‘root’ user is incorrect.
- Password Policy: MySQL has specific password requirements, such as minimum length and complexity. Make sure the password you’re using meets these requirements.
- Privilege Issues: The ‘root’ user might not have the necessary privileges to connect from the ‘localhost’ host. Check the user’s privileges in the MySQL user table.
- Authentication Method: MySQL might be using a different authentication method than the one you’re providing. MySQL 8.0 introduced a new authentication plugin called ‘caching_sha2_password’, which might require a different connection method.
- Connection Parameters: Ensure that you’re specifying the correct host and port in your connection string.
- If you are trying to log in to your MySQL for the first time or you forgoted to set password, while installing mysql. Then you get this ERROR 1698 (28000): Access denied for user ‘root’@’localhost’. There can be two reasons for the error to appear. First of all, you have to not install MySQL correctly. Or forget to set the root user password in MySQL.
To troubleshoot and resolve this issue, you can try the following steps:
- Double-check the password you’re providing for the ‘root’ user. Make sure it’s correct and meets any password policy requirements.
- Verify the privileges of the ‘root’ user using the MySQL
SHOW GRANTS FOR 'root'@'localhost';command.
- If you’re using MySQL 8.0 or newer, you might need to update the authentication method for the ‘root’ user. You can change the authentication method using the ALTER USER statement.
- If you’re still encountering issues, you might need to reset the ‘root’ password if it’s been forgotten or lost.
- Make sure you’re specifying the correct host and port in your connection string.
In this tutorial, you will learn how to solve 1698 (28000) Access denied for user ‘root’@’localhost’ (using password: yes/No).
[Solved] MySQL – ERROR 1698 (28000): Access denied for user ‘root’@’localhost’ (using password: yes/No)
There are two methods to fix following errors, as follows:
- Method 1: Fix error 1698 (28000): Access denied for user using mysql_secure_installation
- Method 2: Fix error 1698 (28000): Access denied for user using Alter
Method 1: Fix error 1698 (28000): Access denied for user using mysql_secure_installation
Now, open your terminal or command line and execute the following command into it to set a password for your MySQL root user:
Once you have executed the above command. After that, a prompt will open on the terminal or command line in which you will have to type the password and confirm the password. Then press enter to set a password for your MySQL root user.
If your error is not resolved even after using the first method, then close the terminal and follow the second method.
Method 2: Fix error 1698 (28000): Access denied for user using Alter
When you install MySQL for the first time into your server or machine, you may not get the option to set a password. If so, you will need to login to MySQL as the root user.
Most of the time, users may try to log in to MySQL as “mysql -u user” or “mysql -u root”, but it won’t work because “user@localhost” has not yet been created on your mysql server, and root cannot be accessed without sudo privileges.
If you try to login to your mysql server using the command “mysql -u root@localhost” then you will get this error:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
So for this, you should use sudo command to login to your mysql server:
sudo mysql -u root
Now you have login to your MySQL server using above command. But there is a small problem that you cannot log in to MySQL without sudo privileges, and MySQL can be accessed by any privileged or sudo user.
To prevent that, you can set a password prompt to appear whenever anyone tries to log in.
Now, execute the following command on terminal or command line to check password mechanism or plugin is attached to your root account:
mysql> SELECT User, plugin from mysql.user ;
Once you have executed the above command. After that, on your terminal, the support of your MySQL Mechanism will be shown like “mysql_native_password” or the latest “caching_sha2_password“ on later version 8.0.0.
If your mysql server supports machines of “caching_sha2_password” then you have to use the below command. So that you can change or update the password of the root user in your MySQL server.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '[ENTER-NEW-PASSWORD]';
Now execute the following command on terminal or command line to restart the server to apply the changes:
sudo systemctl restart mysql.service
That’s all. In this tutorial, you have learned simple two ways on how to resolve 1698 (28000) Access denied for user ‘root’@’localhost’.