ERROR 1698 28000 Access denied for user 'root''localhost'
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Understanding ERROR 1698 (28000): Access denied for user 'root'@'localhost'
When working with MySQL, one might encounter several errors related to user authentication and privileges. One such common error is ERROR 1698 (28000): Access denied for user 'root'@'localhost'. This error is particularly prevalent in MySQL installations that use Unix socket authentication, especially on more secure installations that follow modern security practices. In this article, we will explore the reasons behind this error, provide technical explanations, and suggest solutions with practical examples.
Causes of ERROR 1698 (28000)
Unix Socket Authentication
One primary cause for this error is the use of Unix socket authentication. Unix socket authentication allows MySQL to authenticate users based on the Unix credentials of the client process connecting to it. This means that the MySQL server can be configured to permit a Linux user to connect as a specific MySQL user without needing a password, as long as the connection is made via the localhost.
Security Practices
Modern security configurations encourage more secure authentication methods. In many MySQL installations, particularly on Linux distributions like Ubuntu, MySQL is configured to use auth_socket plugin for the root user by default instead of traditional password authentication. This means that only the Linux user root can access the MySQL root account when connected from localhost, without specifying a password.
How to Verify the Plugin in Use
To understand which authentication method is in use for a MySQL user, you can run the following query:
This will return the authentication plugins associated with the root user. If you see auth_socket listed, then Unix socket authentication is indeed in use.
Solutions to ERROR 1698 (28000)
There are several solutions one can pursue to resolve this error, depending on the desired security profile:
Solution 1: Use sudo to Access MySQL as Root
The simplest way to interact with MySQL when Unix socket authentication is enabled for the root user is to access MySQL using sudo:
This command elevates your privileges to the root user and leverages socket authentication to gain access.
Solution 2: Create a New MySQL Administrative User
Instead of modifying the root user's configuration and potentially reducing the security of your MySQL instance, you can create a new MySQL user with administrative privileges:
Solution 3: Change Authentication Method
If socket authentication is not needed, you can change the root user's authentication plugin back to mysql_native_password:
Note: Changing the authentication plugin may impact the security of your MySQL instance. Always evaluate potential security risks and adhere to best practices.
Key Points Summary
| Issue | Cause | Solution |
| ERROR 1698 (28000) | Unix socket authentication for root user on localhost | Use sudo mysql -u root |
| Security Configuration | MySQL configured with auth_socket plugin for root | Create new MySQL administrative user |
| Authentication Method | Use of auth_socket instead of password-based authentication | Change auth plugin to mysql_native_password |
Conclusion
The ERROR 1698 (28000): Access denied for user 'root'@'localhost' is not a bug or an error in the MySQL software itself; rather, it's a reflection of intentional security measures implemented in certain MySQL configurations. By understanding the underlying causes of this error and the rationale behind Unix socket authentication, administrators can effectively manage MySQL access while maintaining a desired level of security. Always remember that security should be a priority, and potential changes to user authentication should be reviewed with security implications in mind.
Related reading
- ERROR 2002 HY000 Can't connect to local MySQL server through socket '/tmp/mysql.sock
- ERROR 2002 HY000 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 2
- ERROR 2003 HY000 Can't connect to MySQL server on '127.0.0.1' 111
- ERROR 2006 HY000 MySQL server has gone away
- error 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 2' -- Missing /var/run/mysqld/mysqld.sock
- Error Code 1292 - Truncated incorrect DOUBLE value - Mysql
- Error Code 2013. Lost connection to MySQL server during query
- Error creating bean with name 'entityManagerFactory' defined in class path resource Invocation of init method failed

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.