简体   繁体   English

无法创建与数据库服务器MySQL 8.0的连接

[英]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: 但是,我发现了两种防止错误的方法:

  • Run MySQL from a console window and exit. 从控制台窗口运行MySQL并退出。
  • Launch the Workbench and click on "Local instance MySQL57" (That name hasn't changed after the update.) Close the workbench again. 启动工作台,然后单击“本地实例MySQL57”(该名称在更新后没有更改。)再次关闭工作台。

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.

相关问题 无法创建到 MySQL 数据库服务器的 JDBC 连接 - Could not create JDBC connection to MySQL database server 无法建立与数据库服务器的连接-Java MySQL Connector - Could not create connection to database server - java mysql connector 无法建立与数据库服务器的连接-Eclipse MySQL错误 - Could not create connection to database server - Eclipse MySQL error .MySQLNonTransientConnectionException: Could not create connection to database server - .MySQLNonTransientConnectionException: Could not create connection to database server 登录中的异常::无法创建与数据库服务器的连接 - Exception in Login:: Could not create connection to database server 无法通过 Docker 创建与数据库服务器的连接 - Could not create connection to database server via Docker 异常无法创建与数据库服务器的连接 - exception could not create connection to database server 连接到数据库mysql工作台时发生错误:java.sql.SQLNonTransientConnectionException:无法创建与数据库服务器的连接 - Error occur while connecting to database mysql workbench:java.sql.SQLNonTransientConnectionException: Could not create connection to database server MySql 与 azkaban 连接时出现错误“无法创建 PoolableConnectionFactory(无法创建与数据库服务器的连接。)”? - MySql error “Cannot create PoolableConnectionFactory (Could not create connection to database server.)” while connecting with azkaban? 由于“java.sql.SQLNonTransientConnectionException:无法创建与数据库服务器的连接”,无法连接到 mysql 服务器 - Unable to connect to mysql server because of "java.sql.SQLNonTransientConnectionException: Could not create connection to database server"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM