连接到MySQL数据库时的SSL连接警告 [英] Warning about SSL connection when connecting to MySQL database

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

问题描述

下面的两个类,我试过连接到MySQL数据库。但是,我总是遇到这个错误:


Wed Dec 09 22:46:52 CET 2015 WARN:建议不建立服务器身份验证的SSL连接。根据MySQL 5.5.45+,5.6.26+和5.7.6+的要求,如果未设置显式选项,则必须默认建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为false。您需要通过设置useSSL = false来显式禁用SSL,或者设置useSSL = true并提供用于服务器证书验证的truststore。

这是带有 main 方法的测试类:

  public class TestDatabase {

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

这是数据库 class:

  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();
}
}
}


解决方案>

您的连接网址应如下所示:

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

这将禁用SSL并禁止SSL错误。


With the two classes below, I've tried connect to a MySQL database. 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. 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. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

This is the test class with the main method:

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:

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();
        }
    }
}

解决方案

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.

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

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