SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
This error message typically indicates that the MySQL server is unable to authenticate the user 'root'@'localhost' with the provided password.
This error message typically indicates that the MySQL server is unable to authenticate the user root@localhost with the provided password.
In modern MySQL (5.7+) and MariaDB, this is almost always caused by the auth_socket (or unix_socket) authentication plugin. This plugin requires OS-level authentication (running commands with sudo) instead of a password, which breaks standard application connections.
To resolve this, you need to switch the root user to a password-based authentication plugin. Follow these steps:
- Access the MySQL command line using
sudoto bypass the password requirement:sudo mysql - Change the authentication plugin for the
rootuser tomysql_native_password(orcaching_sha2_passwordfor MySQL 8.0+):ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password'; FLUSH PRIVILEGES; EXIT; - Restart the MySQL service to apply changes:
sudo systemctl restart mysql - Test the connection using the new password:
mysql -u root -p
If you are still unable to connect, verify that the MySQL service is running and check the server logs or configuration files (typically /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf) for additional details.