Keywords: MySQL | authentication plugin | ERROR 1524 | Ubuntu | root password reset
Abstract: This article provides an in-depth analysis of the ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded issue in MySQL 5.7+. It explores the root cause related to authentication plugin configuration and presents a comprehensive solution involving root password reset and switching to mysql_native_password plugin. The content also covers related socket connection issues and permission configurations, offering developers complete guidance for resolving MySQL authentication failures in Ubuntu environments.
Problem Background and Error Analysis
After installing MySQL 5.7 on Ubuntu 16.04 environments, users often encounter a series of chain authentication issues. Initial connection attempts may result in socket file missing errors, manifested as ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'. After resolving socket issues, users then face ERROR 1698 (28000): Access denied for user 'root'@'localhost' password authentication failures. The core problem ultimately appears as ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded, indicating that the configured authentication plugin cannot load properly.
Root Cause Investigation
MySQL 5.7+ versions in some Linux distributions default to using the auth_socket plugin for authentication, which relies on system user credentials rather than traditional passwords. When system configurations become inconsistent or issues arise during upgrades, plugin loading fails. In contrast, the traditional mysql_native_password plugin provides more stable password authentication with better compatibility.
Complete Solution
Stop MySQL Service and Enter Safe Mode
First, stop the normal MySQL service and start it in a mode that skips privilege verification:
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
This command starts MySQL without privilege verification, allowing password-free access.
Connect to MySQL and Modify Authentication Configuration
Connect to the MySQL server using:
mysql -uroot
After successful connection, execute the following SQL statements to modify root user authentication configuration:
use mysql;
update user set authentication_string=PASSWORD("") where User='root';
update user set plugin="mysql_native_password" where User='root';
flush privileges;
quit;
The critical step is changing the plugin field value to mysql_native_password, ensuring the use of traditional password authentication mechanism.
Restart MySQL Service and Verify
After completing configuration modifications, restart the MySQL service normally:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
Now you can log in to MySQL with an empty password:
mysql -u root -p
Simply press Enter at the password prompt to successfully log in.
Auxiliary Issue Handling
Socket File Issue Resolution
If encountering socket file-related errors, manually create and set correct permissions:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
Or use a more concise command:
mkdir -p /var/run/mysqld && chown mysql:mysql /var/run/mysqld
Connection Method Optimization
In some cases, using IP address instead of localhost may be more stable:
mysql -uroot -h127.0.0.1
This can avoid some DNS resolution or socket path-related issues.
Technical Principle Deep Analysis
MySQL's authentication plugin system allows different identity verification mechanisms. The auth_socket plugin verifies system user identity through Unix sockets, while mysql_native_password uses traditional SHA1 hash password verification. When system environments change or MySQL upgrades occur, plugin configurations may become inconsistent, leading to authentication failures.
Modifying the authentication plugin to mysql_native_password not only resolves current authentication issues but also provides better cross-environment compatibility. This configuration works stably in both development and production environments, avoiding authentication problems caused by system user changes.
Preventive Measures and Best Practices
To avoid similar issues, it's recommended to check and configure authentication plugins immediately after MySQL installation. For production environments, set strong passwords instead of empty passwords and update passwords immediately after configuration changes:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secure_password';
Regularly check MySQL user tables and plugin configurations to ensure consistency after system upgrades.