Are you getting the following error when trying to login to the MySQL root on an Ubuntu system? We’ll show you how to clear it up in a matter of seconds.
Note: Working with MySQL 8.0.21 on Ubuntu.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
This error is caused by the auth_socket plugin. Simple solution: let’s just disable it. Here the commands you’ll need:
1. Login to MySQL as root (sudo will bypass password prompt)
$ sudo mysql -u root
2. Change to the
mysql database and set the plugin to
mysql_native_password for the root user.
mysql> USE mysql; mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root'; mysql> FLUSH PRIVILEGES;
3. You have to change the root password for this to work. Even just specifying the current password is fine too, but this command must be executed:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here'; mysql> exit;
4. Lastly, restart MySQL for the changes to take effect.
$ sudo systemctl restart mysql
You can now login to MySQL root as normal.
$ mysql -u root -p