连接到MySQL数据库时有关SSL连接的警告

在尝试使用Java连接到MySQL数据库时遇到SSL连接警告。错误提示表明存在SSL配置问题。解决方案包括修改连接URL以禁用SSL,或者使用特定版本的mysql-connector。另外,可以下载OpenSSL并设置环境,或者在开发模式下关闭服务器验证。
部署运行你感兴趣的模型镜像

本文翻译自:Warning about SSL connection when connecting to MySQL database

With the two classes below, I've tried connect to a MySQL database. 在下面的两个类中,我尝试连接到MySQL数据库。 However, I always get this error: 但是,我总是会收到此错误:

Wed Dec 09 22:46:52 CET 2015 WARN: Establishing SSL connection without server's identity verification is not recommended. 2015年12月09日星期三22:46:52警告:不建议在没有服务器身份验证的情况下建立SSL连接。 According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. 根据MySQL 5.5.45 +,5.6.26 +和5.7.6+的要求,如果未设置显式选项,则默认情况下必须建立SSL连接。 For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. 为了与不使用SSL的现有应用程序兼容,将verifyServerCertificate属性设置为'false'。 You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 您需要通过设置useSSL = false来显式禁用SSL,或者设置useSSL = true并为服务器证书验证提供信任库。

This is the test class with the main method: 这是带有main方法的测试类:

public class TestDatabase {

    public static void main(String[] args) {
        Database db = new Database();
        try {
            db.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        db.close();
    }
}

This is the Database class: 这是Database类:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Database {

    private Connection con;

    public void connect() throws Exception{

        if(con != null) return;

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new Exception("No database");
        }

        String connectionURL = "jdbc:mysql://localhost:3306/Peoples";

        con = DriverManager.getConnection(connectionURL, "root", "milos23");        
    }

    public void close(){
        if(con != null){
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

#1楼

参考:https://stackoom.com/question/2JSJg/连接到MySQL数据库时有关SSL连接的警告


#2楼

Your connection URL should look like the below, 您的连接网址应如下所示,

jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false

This will disable SSL and also suppress the SSL errors. 这将禁用SSL并抑制SSL错误。


#3楼

An alternative method would be: 一种替代方法是:

Properties properties = new Properties();
properties.setProperty("user", "root");
properties.setProperty("password", "milos23);
properties.setProperty("useSSL", "false");
properties.setProperty("autoReconnect", "true");

try (Connection conn = DriverManager.getConnection(connectionUrl, properties)) {
...
} catch (SQLException e) {
...
}

Although, I don't think the auto-reconnect setting is needed to remove the warning. 虽然,我认为不需要自动重新连接设置即可删除警告。


#4楼

the new versions of mysql-connector establish SSL connection by default ...to solve it: 新版本的mysql-connector默认情况下建立SSL连接...以解决该问题:

Download the older version of mysql-connector such as mysql-connector-java-5.0.8.zip 下载较旧版本的mysql-connector,例如mysql-connector-java-5.0.8.zip

. . or . 要么 。 . Download OpenSSL for Windows and follow the instructions how to set it 下载适用于Windows的OpenSSL并按照说明进行设置


#5楼

Use this to solve the problem in hive while making connection with MySQL 与MySQL建立连接时,用它来解决蜂巢中的问题

<property>
   <name>javax.jdo.option.ConnectionURL</name>
   <value>jdbc:mysql://localhost/metastore?createDatabaseIfNotExist=true&amp;autoReconnect=true&amp;useSSL=false</value>
   <description>metadata is stored in a MySQL server</description>
</property>

#6楼

如何使用SSL但关闭服务器验证(例如在您自己的计算机上处​​于开发模式时):

jdbc:mysql://localhost:3306/Peoples?verifyServerCertificate=false&useSSL=true

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值