我无法使用此代码从 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 不起作用(协议(protocol)被禁用或密码套件不合适是 TLS 行话。)
试试这个连接字符串:jdbc:mysql://localhost:3300/sys
(无 TLS)。它可能会起作用。
然后试试这个连接字符串jdbc:mysql://localhost:3306/sys
.它使用默认值。
设置 MySQL 服务器以使用 TLS takes some server engineering work and knowledge .可能没有正确完成。如果有人为您这样做,请向该人寻求帮助。
关于java - mysql jdbc驱动中的通信链路故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68891210/