[JPA] communications link failure 오류 해결방법 (1012)

2022. 10. 13. 22:26Web Developer/SpringBoot/JPA

    JPA 예제를 작성 후 실행해봤는데 Communications link failure 오류가 발생했다.

    우선 콘솔을 살펴보니 아래와 같았다.

    2022-10-12 22:14:19.790 ERROR 5984 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 2022-10-12 22:14:19.795 ERROR 5984 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution 2022-10-12 22:14:19.797 INFO 5984 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2022-10-12 22:14:19.803 INFO 5984 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-10-12 22:14:19.812 ERROR 5984 --- [ main] o.s.boot.SpringApplication : Application run failed

    검색해보니 JDBC 연결이 되지 않았을 때 발생할 수 있는 오류라고 한다.

    application.properties 내 설정을 추가하라는 글도 있었지만, 내 경우엔 설정은 제대로 되어 있고 오타도 없었다.

    다음으로는 MySQL 연결과 데이터베이스가 정상적으로 존재하는지, 제대로 연결했는지 여부를 확인하기로 했다.

    Information의 No connection established 문구가 보인다. 기존에 정상적으로 MySQL 실행 시 보이지 않았던 문구다.

    작업 관리자로 들어가보니 내 경우에는 MySQL이 중지 상태였다. MySQL80을 다시 실행해준다.

    아까와 달리 정상적으로 연결된 것을 볼 수 있다.

    다시 실행해봤지만 안 된다. 이제 데이터베이스가 정상적으로 존재하는지를 확인해본다.

    show databases; 명령어를 실행해

    application.properties의 spring.datasource.url에 작성한 DB명과 MySQL Database의 DB명이 일치하는지 확인한다.

    내 경우 프로젝트에 사용할 데이터베이스명과 코드에 작성한 데이터베이스명이 달라 오류가 발생했다.

    해당 DB 없을 경우 create database dbName; 명령어로 데이터베이스를 생성하면 된다.

    실행하면 작성한 코드가 정상적으로 작동하는 것을 볼 수 있다.

    맨 위로