[英]Could not create connection to database server, MySQL 8.0
This error has already been dealt with several times in the forum, but I meet the error for the first time after updating to MySQL 8.0 and the solutions proposed for previous versions didn't work. 该错误已经在论坛中处理过几次,但是在更新到MySQL 8.0之后我第一次遇到该错误,并且以前版本提出的解决方案不起作用。 I found, however, two ways to prevent the error: 但是,我发现了两种防止错误的方法:
Having done so, the error will not happen any more until I restart the PC. 这样做后,直到我重新启动PC,该错误才会再发生。 Launching "Computer Management" (Win10) and looking at the services, I see "MySQL80" with a status of "Running" right after PC startup. 启动“计算机管理”(Win10)并查看服务,我在PC启动后立即看到状态为“正在运行”的“ MySQL80”。 So that seems to be ok. 这样看来还可以。
I am using MySQL Server version: 8.0.12 and mysql-connector-java 8.0.12. 我正在使用MySQL服务器版本:8.0.12和mysql-connector-java 8.0.12。
Here's the java code I use to get a connection. 这是我用来获得连接的Java代码。 With 8.0 I had to add time zone information to make it work. 对于8.0,我必须添加时区信息才能使其正常工作。 See what other flags I tested as well. 查看我还测试了哪些其他标志。
import java.sql.*;
import java.util.*;
public class Test {
String url= "jdbc:mysql://localhost/myDb?autoReconnect=true&useSSL=false";
public Test() {
try {
Connection conn= DriverManager.getConnection(url+"&serverTimezone=CET",
// "&useJDBCCompliantTimezoneShift=true"+
// "&useUnicode=true&characterEncoding=UTF-8"+
// "&zeroDateTimeBehavior=CONVERT_TO_NULL",
"root",
"mypass");
System.out.println(conn);
}
catch(SQLException e) {
System.out.println(e);
}
System.exit(0);
}
public static void main(String args[]) {
EventQueue.invokeLater(Test::new);
}
}
Edit: Just updated to server and J/Connector 8.0.13, but the java.sql.SQLNonTransientConnectionException persists. 编辑:刚刚更新到服务器和J / Connector 8.0.13,但java.sql.SQLNonTransientConnectionException仍然存在。
In my given test case one has to remove "&useSSL=false". 在我给定的测试用例中,必须删除“&useSSL = false”。
In Connector/J 8.0 "useSSL" has been replaced by "sslMode" and "useSSL" has, indeed, been deprecated. 在Connector / J 8.0中,“ useSSL”已替换为“ sslMode”,而实际上已弃用了“ useSSL”。 But to me "deprecated" doesn't mean "illegal". 但是对我而言,“已弃用”并不意味着“非法”。 So now we know: Beware of deprecation! 现在我们知道了:提防贬值!
At least at my location (central Europe) specifying serverTimezone seems to be a must (Runtime error). 至少在我的位置(中欧),指定serverTimezone似乎是必须的(运行时错误)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.