如果你在Debian/Ubuntu操作系统上遇到MySQL错误:ERROR 1524 (HY000): Plugin ‘unix_socket’ is not loaded(插件'unix_socket'未加载),请采取以下方法解决。可先参考修复MariaDB出现Plugin ‘unix_socket’ is not loaded Error的方法。
背景
最近遇到了这个错误:ERROR 1524 (HY000): Plugin ‘unix_socket’ is not loaded,未在我的Debian 9服务器上加载成功,同时尝试以root用户身份向MariaDB数据库进行身份验证,经过查找后,我发现此错误的解决方法是使用mysqld_safe启动MySQL服务并重置root密码。
解决方法
第1步:停止mysql服务
请先停止MySQL服务:
$ sudo systemctl stop mysql
或者:
$ sudo /etc/init.d/mysql stop
第2步:使用mysqld_safe启动mysql
然后使用mysqld_safe和选项--skip-grant-tables启动mysql服务,并继续运行:
$ sudo mysqld_safe --skip-grant-tables &
[1] 8197
第3步:重置root用户密码
打开MySQL终端控制台,输入mysql -uroot命令:
$ mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.14-MariaDB-1:10.3.14+maria~stretch mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
你应该没有密码验证到MySQL终端,现在切换到mysql数据库,运行USE mysql;命令:
MariaDB [(none)]> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
然后进行重置root用户密码:
MariaDB [mysql]> update user set password=PASSWORD("NewRootPassword") where User='root';
Query OK, 0 rows affected (0.002 sec)
Rows matched: 1 Changed: 0 Warnings: 0
注:将NewRootPassword替换为root用户的新密码。
还将身份验证插件设置为本机:
MariaDB [mysql]> UPDATE USER SET plugin="mysql_native_password";
Query OK, 2 rows affected (0.001 sec)
Rows matched: 2 Changed: 2 Warnings: 0
最后关闭数据库会话:
MariaDB [mysql]> quit;
Bye
第4步:重置root用户密码
以标准方式重新启动mysql服务,但首先要停止服务:
$ sudo systemctl stop mysql
或者:
$ /etc/init.d/mysql stop
确保没有其他进程正在运行:
ps aux | grep mysql
启动mysql:
sudo systemctl start mysql
以root用户身份测试访问权限:
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.14-MariaDB-1:10.3.14+maria~stretch mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> QUIT
Bye
注:操作完以上步骤后,错误就能得到解决了。
相关主题