Mariadb 连接客户端:在 mysql 8.0 上拒绝用户访问(使用密码:NO)

Ton*_*hua 5 java mysql mariadb

mariadb-java-client 在 mysql 8.0 上抛出访问被拒绝,但适用于 mysql 5.6 所以我想知道 mariadb 客户端是否与 mysql 8.0 兼容

  1. 在mysql中,测试用户被设置为hosts machine = %

  2. 甚至在 mysql 8.0 的机器上测试,同样的访问被拒绝错误。


Caused by: java.sql.SQLException: Access denied for user 'user1'@'192.168.238.1' (using password: NO)
Current charset is UTF-8. If password has been set using other charset, consider using option 'passwordCharacterEncoding'
Run Code Online (Sandbox Code Playgroud)
    Connection connection = DriverManager.getConnection("jdbc:mariadb://192.168.0.2:3306/test", "user1", "admin@123");
    Statement stmt = connection.createStatement();
    stmt.executeUpdate("CREATE TABLE a (id int not null primary key, value varchar(20))");
    stmt.executeUpdate("DROP TABLE a");
    stmt.close();
    connection.close();
Run Code Online (Sandbox Code Playgroud)

mysql 5.6 和 8.0 上的用户名和密码相同

  1. 成功:'mariadb-java-client',版本:'2.3.0',mysql 5.6

  2. 失败:'mariadb-java-client',版本:'2.3.0',mysql 8.0

  3. 成功:'mysql-connector-java',版本:'8.0.13' mysql 8.0 (jdbc:mysql://....)

小智 6

MySQL 8 使用 caching_sha2_password 而不是 MySQL 5.7(和 MariaDB)的 mysql_native_password。

“caching_sha2_password,它是 MySQL 8.0 的首选身份验证插件,也是默认身份验证插件而不是 mysql_native_password。此更改影响服务器和 libmysqlclient 客户端库:”

https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

MariaDB 的 Java 连接器尚未实现此功能,但已分配了一项任务:

https://jira.mariadb.org/browse/CONJ-663

为了连接到 MySQL 8,您必须使用 Oracle 连接器,另一个支持更改的连接器,或者等待 MariaDB 实施。

  • 谢谢...我用“mysql_native_password”更新了我的 Mysql 用户密码,它起作用了。```ALTER USER 'root'@'localhost' 通过 'password' 识别 mysql_native_password; ```` (3认同)