MySQL ERROR 1698 (28000): Access denied for user 'root'@'localhost' (Solution)
To fix the the error "ERROR 1698 (28000): Access denied for user 'root'@'localhost'", change the root MySQL user authentication method from auth_socket
to mysql_native_password
.
Let's go through the steps of how to do this on a server.
Step 1
Login to the mysql
server in sudo
mode as the root user and supply any required passwords.
sudo mysql -u root -p
Step 2
Within the mysql
console run the following commands to set the root MySQL user to use mysql_native_password
:
USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;
Step 3
Restart the mysql
server to ensure the new changes are applied:
sudo service mysql restart
Conclusion
You can now login to MySQl as root user without having to use sudo mode like this:
mysql -u root -p
This also means you should have no issues connecting to mysql remotely using a database client with a regular user over SSH.