无法通过SunCertPathBuilderException连接到MySQL数据库 [英] Unable to connect to MySQL database with SunCertPathBuilderException

查看:231
本文介绍了无法通过SunCertPathBuilderException连接到MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到MySQL数据库:

I'm trying to connect to MySQL database:

       static final String URL="jdbc:mysql://localhost:3306/demo_hotels?useSSL=true&autoReconnect=true&serverTimezone=UTC";
       static final String USERNAME="demo";
       static final String PASSWORD="demo";

        public static void main(String[] args) {
         try {
          DriverManager.registerDriver(new FabricMySQLDriver());
          connection=DriverManager.getConnection(URL, USERNAME, PASSWORD);

          Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new
                JdbcConnection(connection));
          Liquibase liquibase = new liquibase.Liquibase("db/db.changelog.xml",
                new ClassLoaderResourceAccessor(), database);

          liquibase.update(new Contexts(), new LabelExpression());
          database.close();

         } catch (SQLException | LiquibaseException e) {
          e.printStackTrace();
         }

此功能正常。但是现在我试图在另一台机器上执行此代码,但它不起作用:

This was working. But now I'm trying to execute this code on another machine and it doesn't work:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
   at com.pazukdev.auxiliary_services.DBService.main(DBService.java:69)
    Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
   at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)

为什么停止工作?

旧计算机:java版本1.8.0_112,Windows 7,MySQL Server 5.7.21

Old machine: java version 1.8.0_112, Windows 7, MySQL Server 5.7.21

新机器:java版本1.8.0_172,Windows 10,MySQL Server 8.0.11

New machine: java version 1.8.0_172, Windows 10, MySQL Server 8.0.11

我发现了一些有关此类的信息某种例外。看来我的SSL证书有一些问题:接受服务器的自我Java客户端中的签名ssl证书

I found some information about such kind of exceptions. It look like I have some triobles with SSL certificate: Accept server's self-signed ssl certificate in Java client

但是带有TrustManager的选项2不起作用-我有相同的异常。
我尝试输入cmd:

But Option 2 with TrustManager not works - I have the same Exception. I tried to type in cmd:

<JAVA_HOME>\bin\keytool -import -v -trustcacerts
-alias server-alias -file server.cer
-keystore cacerts.jks -keypass changeit
-storepass changeit

但是我也没有从选项1中获得任何影响。

But I have no eny effect from this Option 1 too.

也许我做错了..

推荐答案

我不是Java开发人员,但是我在这里有一些疑问和疑问。

I'm not Java developer, but I have some doubts and questions here.


  1. 如果您使用本地数据库,实际上需要吗?useSSL = true 吗?
  2. cmd执行的结果是什么?您是否已正确导出与本地主机相对应的 server.cer 文件?有必要的密码和商店密码?

  1. Do you actually need for ?useSSL=true if you're using local db?
  2. What are the results of your cmd execution? Did you have correctly exported server.cer file corresponds to your local host? With necessary keypass and storepass?

这篇关于无法通过SunCertPathBuilderException连接到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆