ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
When you try to login to the MySQL database with the root user, you get the “ERROR 1698 (28000): Access denied for user ‘root’@’localhost'” error.
Some systems like Ubuntu, mysql is using by default the UNIX auth_socket plugin.
Connect to your database and run commands
mysql> USE mysql; mysql> SELECT User, Host, plugin FROM mysql.user;
output:
+------------------+-----------------------+ | User | plugin | +------------------+-----------------------+ | root | auth_socket | | mysql.sys | mysql_native_password | | debian-sys-maint | mysql_native_password | +------------------+-----------------------+
As you can see in the output, the root
user is using the auth_socket
plugin
There are 2 ways to solve this:
First option:
mysql> USE mysql; mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> exit; $ service mysql restart
Second option (recommended):
mysql> USE mysql; mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY ''; mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost'; mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER'; mysql> FLUSH PRIVILEGES; mysql> exit; $ service mysql restart
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0