Thu. Dec 12th, 2019

Fix ERROR 1698 (28000): Access denied for user ‘root’@’localhost’ in MySQL

1 min read

Recently, when I try to install and create a database in MySQL, I got “ERROR 1698 (28000): Access denied for user ‘root’@’localhost’” error. After that, I found a method for this bug. So this article shows how to fix this bug.

After the installation is complete, the following error occurs when logging in to MySQL:

  1. Add “skip-grant-tables” line to mysqld.cnf file using the command:
    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
  2. Restart mysql-server
    sudo service mysql restart
  3. Change permission for root user mysql with the command:
    mysql -u root -p
    use mysql;
    update user set authentication_string=password(“your_password”) where user=”root”;
    flush privileges;
    select user,plugin from user;
    update user set authentication_string=password(“your_password”),plugin=’mysql_native_password’ where user=’root’;
  4. Remove or add comment character (#) to “skip-grant-tables” line on mysqld.cnf file and restart mysql server
  5. Enjoy!