link mysql jdbc 驱动程序中的通信失败

Communication link failure in mysql jdbc driver

我无法使用此代码

与 java 的 mysql 建立连接
 Connection con=null;
    String dbUrl="jdbc:mysql://localhost:3300/sys?useSSL=true";
    String driver = "com.mysql.cj.jdbc.Driver";
    String userName = "root";
    String password = "cool123";

    Class.forName(driver).getDeclaredConstructor().newInstance();
    con = DriverManager.getConnection(dbUrl,userName,password);

它向我抛出这个错误 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The driver has not received any packets from the server. No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

您正在尝试使用传输层安全性(TLS 或 SSL)连接到您的服务器。那是因为您的连接字符串显示 ?useSSL=true。当您连接到 localhost 时,这有点奇怪——没有传输进出您的 Java 程序运行的服务器,因此如果您使用 TLS 会花费大量额外的计算周期而没有太大好处甚至可以让它工作。

您的错误消息提示 TLS 无法正常工作(协议被禁用或密码套件不合适 是 TLS 行话。)

试试这个连接字符串:jdbc:mysql://localhost:3300/sys(无 TLS)。可能有用。

然后试试这个连接字符串 jdbc:mysql://localhost:3306/sys。它使用默认值。

正在设置 MySQL 服务器以使用 TLS takes some server engineering work and knowledge。这可能没有正确完成。如果有人为你做了,请向那个人寻求帮助。