Cảnh báo Establishing SSL connection without server's identity verification is not recommended xuất hiện từ MySQL Connector/J 5.1.35+. Để tắt, thêm tham số useSSL=false vào JDBC URL.
Cú pháp JDBC URL
jdbc:mysql://localhost:3306/ten_database?autoReconnect=true&useSSL=false
Ví dụ mã Java
import java.sql.Connection;
import java.sql.DriverManager;
public class AvoidSQLWarnDemo {
public static void main(String[] args) {
String JdbcURL = "jdbc:mysql://localhost:3306/mybusiness?"
+ "autoReconnect=true&useSSL=false";
String Username = "root";
String password = "123456";
Connection con = null;
try {
con = DriverManager.getConnection(JdbcURL, Username, password);
System.out.println("Your JDBC URL is as follows: " + JdbcURL);
} catch (Exception exec) {
exec.printStackTrace();
}
}
}
Giải thích tham số
useSSL=false: Tắt kết nối SSL, loại bỏ cảnh báoautoReconnect=true: Tự động kết nối lại khi mất kết nốiverifyServerCertificate=false: (Tùy chọn) Không xác thực chứng chỉ server nếu dùng SSL
Khi nào nên dùng SSL?
- Môi trường production: Nên bật SSL (
useSSL=true) và cấu hình truststore - Môi trường development/local: Có thể tắt SSL để tránh cảnh báo
Lưu ý: MySQL 8.0+ mặc định yêu cầu SSL. Nếu tắt, đảm bảo mạng nội bộ an toàn.