执行JDBC程序时,连接到数据库时出现以下错误:
Exception in thread "main" com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775) at com.mysql.jdbc.Connection.
(Connection.java:1555) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at main.java.MyFirstJdbcProgram.readDataBase(MyFirstJdbcProgram.java:23) at main.java.Main.main(Main.java:6) 在研究此问题时,我知道以下错误是因为我需要向用户授予特权,所以请按照以下步骤操作
mysql -u root -p 然后输入密码 然后我跑了
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'mypassword';
我也用过
UPDATE user SET authentication_string=password('mypassword') WHERE user='root'; 但是我正在错误以下
错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'IDENTIFIED BY'mypassword'附近使用