Java에서 MySQL 데이터베이스에 연결할 때 '서버의 신원 확인 없이 SSL 연결을 설정하는 것은 권장되지 않습니다'라는 경고 메시지가 출력되는 경우가 있습니다. 이 경고를 간단히 비활성화하려면 JDBC URL에 다음 옵션을 추가하면 됩니다.
autoReconnect=true&useSSL=false
JDBC URL 전체 작성 형식
완전한 JDBC URL 문법은 아래와 같습니다.
String jdbcURL = "jdbc:mysql://localhost:포트번호/데이터베이스명?autoReconnect=true&useSSL=false";
경고가 발생하는 이유
useSSL=false 옵션을 지정하지 않으면 콘솔에 다음과 같은 경고 메시지가 표시됩니다.
Wed Feb 06 18:53:39 IST 2019 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.
MySQL 5.5.45+, 5.6.26+, 5.7.6+ 버전부터는 별도의 옵션을 설정하지 않으면 기본적으로 SSL 연결을 사용하도록 요구합니다. 따라서 개발 환경 등에서 SSL이 필요 없다면 useSSL=false로 명시적으로 비활성화하거나, 반대로 useSSL=true로 설정한 후 서버 인증서 검증용 truststore를 제공해야 합니다.
경고 없이 연결하는 Java 코드 예제
위에서 소개한 문법을 적용하면 경고 메시지를 피할 수 있습니다. 실제 동작하는 전체 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();
}
}
}위 프로그램을 실행하면 더 이상 SSL 관련 경고가 출력되지 않으며, JDBC URL 정보가 정상적으로 콘솔에 표시됩니다.
정리
- 개발·테스트 환경에서 SSL이 불필요한 경우:
useSSL=false옵션 추가 - 운영 환경에서 보안이 중요한 경우:
useSSL=true설정 후 truststore로 서버 인증서 검증
이처럼 JDBC URL에 옵션 한 줄만 추가하면 불필요한 경고를 손쉽게 제거할 수 있습니다.