Error Resolved: 1698 (28000) Access Denied for User ‘root’@’localhost’

With our easy steps, you can easily solve error 1698 (28000) Access denied for the user.

This error is very common when you try to log in to your MySQL for the first time.

Personally, I too faced this issue multiple times, maybe because we were not following the right way to install MySQL, or we forgot to set a password, or else we didn’t get the options to set a password.

Similarly, there may be many other reasons for the above error, but the solution to this error is pretty simple and easy. In this article, you will find a way to resolve 1698 (28000) Access denied for user ‘root’@’localhost’.

There are two ways to resolve this error.

First, you will see a simple and less time-consuming method. If the first method didn’t work in your case, then go to the second one.

Method 1: The Easiest Way to Fix Error 1698 (28000): Access Denied for User

One of the easiest ways to resolve this error is to invoke “mysql_secure_installation”, which will ask you to set a password for your MySQL root user.

$ sudo mysql_secure_installation 

You need to enter a new password and, for confirmation, re-type that password.

If the password is less than 25 characters, you will be prompted to confirm whether you want to continue or not. If you don’t want to set password characters more than 25, simply type “n”.

solve error 1698 (28000) Access denied for user: Fix error using mysq_secure_installation
Fix error using mysql_secure_installation

In my case, it didn’t work and threw me an error on-screen:

“Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server.

Please consider using ALTER USER instead if you want to change authentication parameters.”

If the same thing happens with you too, then close the terminal and follow the second set of steps, which worked in my case to solve error 1698 (28000) Access denied for user.

Method 2: Fix Error 1698 (28000): Access Denied for User using Alter

When you install MySQL for the first time, there is a chance you will not find the option to set a password because of the new method of authenticating users.

If it is like that, then you need to login to MySQL as a 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 system, and root cannot be accessed without sudo privileges.

And when you try to log in as the root user with “mysql -u root@localhost”, you will get the below error.

MySQL Error 1698(2800) Access denied
MySQL Error 1698(2800)

Check the Authorization Mechanism

To resolve this, you must log into MySQL as a sudo on the new installation because the account that is linked with MySQL is the “root” account, not the “user” account.

Run the below command in your terminal:

$ sudo mysql -u root

Once you are logged in, you will find the MySQL console looking like the below-shown image.

Login to MySQL with sudo
Login to MySQL with sudo

Now you can access your MySQL account with the above command, but there is a small problem with this: you cannot log in to MySQL without sudo privileges.

To fix that, you can create a new user and grant the necessary privileges, or else change the password authentication mechanism of the root account.

There are different types of password mechanisms supported by MySQL by default you will find “auth_socket” for your root account to make it robust you can choose conventional “mysql_native_password” or the latest caching_sha2_password on later version 8.0.0

If you want to learn more about authentication plugins, then do check out MySQL authentication documentation.

Before moving to the next step, you should check what password mechanism or plugin is attached to your root account.

To find out, you can run the following queries on the MySQL console:

mysql> SELECT User, plugin from mysql.user ;

The behavior of the above command is shown below:

Check password plugin in MySQL

Set a password on the root account

Now you can set or update your password by following the below snippet. Make sure to replace [ENTER-NEW-PASSWORD] with your password and, prior to that, select the MySQL database.

mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'caching_sha2_password' BY '[ENTER-NEW-PASSWORD]';


Set Password on MySQL
Set Password on MySQL

I’m using “caching_sha2_password”.

If you want to use “mysql_native_password” on > MySQL 5.7 version, type the below queries on your MySQL console.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '[ENTER-NEW-PASSWORD]';

Once the changes have been implemented, restart the MySQL service.

$ sudo systemctl restart mysql.service

And once the service is restarted, type the below code in your terminal and enter the password which you have set above.

$ mysql -u root -p


Login to MySQL after resolving error
Login back to MySQL after resolving the error

Wrapping Up

That’s all to resolve error 1698 (28000) Access denied for user on MySQL.

I’m sure after following the above steps you will be able to resolve the issue, but if you are still having any issues, then do let me know in the comment section.

If you are interested in learning about how to change the MySQL port number, then check out this article.

See you later in the next article.

This Post Has 6 Comments

  1. Grony

    Thank you so much, I couldn’t find REAL help anywhere else 🙂

  2. Абдуррахим

    Thank you very much

    1. Gagan Mishra


  3. Jana

    Oh my God, I’ve spent 2 hours solving the problem with StuckOwerflow and with ChatGPT and nothing could help but your explanation. Thanks a lot!!!

    1. Gagan Mishra

      Sounds good!

  4. contrera_lean

    Thank you, dude!!!!!!!!! ChatGPT cannot help me with this problem. Lol. Gretting from Argentina.

Leave a Reply