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



This error happened right after I used apt to install MySQL 5.7 in Ubuntu 18.04, when I tried to log in as root, the error message shows

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

Then I checked debian.cfg file located in /etc/mysql/, the file shows the user is debian-sys-maint, and the password is random generated. I can log in MySQL using this account.


Since I can log in, I executed the following command in MySQL shell.

USE mysql;
SELECT User, Host, plugin FROM mysql.user;

The result shows the root account is using auth_socket plugin, that’s the reason why the error occurs.

  1. Switch auth_socket plugin to mysql_native_password, same as the debian-sys-maint account using.
    • Execute in MySQL shell
      USE mysql;
      UPDATE user SET plugin='mysql_native_password' WHERE User='root';
  2. Commands above will do the trick, then you can log in MySQL successfully by executing
    mysql -u root

    You can set the root password after logging in.


电子邮件地址不会被公开。 必填项已用*标注