如何在Debian/Ubuntu上解决MySQL错误:错误1524(HY000):未加载插件unix_socket

时间:2020-02-23 14:32:14  来源:igfitidea点击:

我最近遇到此错误ERROR 1524(HY000):在尝试以root用户身份向MariaDB数据库进行身份验证时,未在我的Debian 9服务器上加载插件unix_socket。
ERROR 1524 (HY000): Plugin unix_socket is not loaded
经过一番谷歌搜索后,我发现此错误的解决方法是使用" mysqld_safe"启动MySQL服务并重置root密码。

停止mysql服务

停止MySQL服务。

$sudo systemctl stop mysql
OR
$sudo /etc/init.d/mysql stop

使用mysqld_safe启动mysql

然后用mysqld_safe和选项--skip-grant-tables启动mysql服务,并继续在后台运行它。

$sudo mysqld_safe --skip-grant-tables &
[1] 8197

重设root用户密码

打开MySQL终端控制台。

$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, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

我们应该在没有密码身份验证的情况下进入MySQL终端。现在切换到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

用root用户的新密码替换NewRootPassword

还将身份验证插件设置为本地。

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

正常启动MySQL服务

以标准方式重启mysql服务。但是首先停止服务。

$sudo systemctl stop mysql
OR
$/etc/init.d/mysql stop

确保没有其他进程在运行。

ps aux | grep mysql

启动mysql。

sudo systemctl start mysql

以root用户身份测试访问。

$mysql -u root -p
Enter password: <Enter Password Set>
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, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> QUIT
Bye