将 MySQL 身份验证插件更改为 `caching_sha2_password`

时间:2021-03-11 22:14:05

标签: mysql mariadb

我在 xampp 7.4.1-1 机器上运行 Ubuntu 18.4 LTS

尝试连接到远程数据库时,我收到以下警告:

Warning: mysqli::__construct(): Unexpected server response while doing caching_sha2 auth: 109 in /home/admin/Desktop/Code/project/src/testMySQLConnection.php on line 2

我的文件如下所示:

<?php
$mysqli = new mysqli("127.0.0.1", "root", "myPassword", "test_db", 3306);

/* check connection */
if ($mysqli->connect_errno) {
    mysqli_debug("/home/admin/Desktop/client.trace");
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

我尝试了以下方法来解决上述警告:

admin@admin-VirtualBox:~$ /opt/lampp/bin/mysql -u root
Warning: World-writable config file '/opt/lampp/etc/my.cnf' is ignored
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 72
Server version: 10.4.11-MariaDB Source 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)]> 
MariaDB [(none)]> 
MariaDB [(none)]> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------+-----------------------+--------+-----------+
| user | authentication_string | plugin | host      |
+------+-----------------------+--------+-----------+
| root |                       |        | localhost |
| root |                       |        | 127.0.0.1 |
| root |                       |        | ::1       |
|      |                       |        | localhost |
| pma  |                       |        | localhost |
+------+-----------------------+--------+-----------+
5 rows in set (0.002 sec)

MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BY ''' at line 1
MariaDB [(none)]> 

但是,我收到了上述错误。

任何建议如何将更改 MySQL 身份验证插件更改为 caching_sha2_password

感谢您的回复!

1 个答案:

答案 0 :(得分:1)

评论https://mariadb.com/kb/en/alter-user/

语法是以下形式之一:

1440m

还有其他一些形式。但是您以 MariaDB 无法识别的方式将 ALTER USER 'root'@'localhost' IDENTIFIED BY ''; ALTER USER 'root'@'localhost' IDENTIFIED BY PASSWORD '*975B2CD4FF9AE554FE8AD33168FBFC326D2021DD'; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password USING '*975B2CD4FF9AE554FE8AD33168FBFC326D2021DD'; BY 混合在一起。

相关问题