eclipse连接数据库,一直报错:CLIENT_PLUGIN_AUTH is required,帮我解决下

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;


public class MysqlJdbc {

  public static void main(String args[]) {

    try {

      Class.forName("com.mysql.cj.jdbc.Driver");     //加载MYSQL JDBC驱动程序   

     System.out.println("成功");

    }

    catch (Exception e) {

      System.out.print("失败");

      e.printStackTrace();

    }

    try {

    Connection connect = DriverManager.getConnection(

    "jdbc:mysql://localhost:3306/123"," root","123");

           //连接URL为   jdbc:mysql//服务器地址/数据库名  ,后面的2个参数分别是登陆用户名和密码

      System.out.println("成功连接数据库");

      Statement stmt = connect.createStatement();

      ResultSet rs = stmt.executeQuery("select * from user");

                                                              //user 为你表的名称

while (rs.next()) {

        System.out.println(rs.getString("name"));

      }

    }

    catch (Exception e) {

      System.out.print("错误开始 : ");

      e.printStackTrace();

    }

  }

}



错误提示:

成功

错误开始 : java.sql.SQLNonTransientConnectionException: CLIENT_PLUGIN_AUTH is required

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:550)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:537)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:527)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:512)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:480)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:498)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:494)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:72)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1634)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:637)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:351)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224)

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at com.meiju.com.MysqlJdbc.main(MysqlJdbc.java:19)

Caused by: com.mysql.cj.core.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)

at com.mysql.cj.mysqla.io.MysqlaProtocol.rejectConnection(MysqlaProtocol.java:319)

at com.mysql.cj.mysqla.authentication.MysqlaAuthenticationProvider.connect(MysqlaAuthenticationProvider.java:207)

at com.mysql.cj.mysqla.io.MysqlaProtocol.connect(MysqlaProtocol.java:1361)

at com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:132)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1754)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1624)

... 6 more


_耀儿
浏览 38869回答 3
3回答

JustWannaHugU

jar包的事情吧重新用回mysql-connector-java-5.x.jar版本的试一下

sunbeamWen

要么换jar包,要么更新数据库版本

学者4116497

用5.x的jar包,完美解决
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
MySQL