인프런 커뮤니티 질문&답변
작성자 없음
작성자 정보가 삭제된 글입니다.
MYSQL 연동오류 원인
작성
·
93
0
application.propertes
spring.application.name=apiServer
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/apidb
spring.datasource.username=apidbuser
spring.datasource.password=apidbuser
MySQL
CREATE USER 'apidbuser'@'localhost' IDENTIFIED BY 'apidbuser';
CREATE USER 'apidbuser'@'%' IDENTIFIED BY 'apidbuser';
GRANT ALL PRIVILEGES ON . TO 'apidbuser'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO 'apidbuser'@'%' WITH GRANT OPTION;

현재 데이터베이스 연결은 잘된거 같은데 연결할때마다
oading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2025-03-16T15:58:11.685+09:00 INFO 58817 --- [apiServer] [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2025-03-16T15:58:11.687+09:00 WARN 58817 --- [apiServer] [ restartedMain] c.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2025-03-16T15:58:11.855+09:00 INFO 58817 --- [apiServer] [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@6077b088
2025-03-16T15:58:11.856+09:00 INFO 58817 --- [apiServer] [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2025-03-16T15:58:11.878+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2025-03-16T15:58:11.900+09:00 INFO 58817 --- [apiServer] [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.6.8.Final
2025-03-16T15:58:11.911+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2025-03-16T15:58:12.010+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2025-03-16T15:58:12.061+09:00 INFO 58817 --- [apiServer] [ restartedMain] org.hibernate.orm.connections.pooling : HHH10001005: Database info:
Database JDBC URL [Connecting through datasource 'HikariDataSource (HikariPool-1)']
Database driver: undefined/unknown
Database version: 9.1
Autocommit mode: undefined/unknown
Isolation level: undefined/unknown
Minimum pool size: undefined/unknown
Maximum pool size: undefined/unknown
2025-03-16T15:58:12.353+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2025-03-16T15:58:12.354+09:00 INFO 58817 --- [apiServer] [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2025-03-16T15:58:12.369+09:00 WARN 58817 --- [apiServer] [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2025-03-16T15:58:12.506+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2025-03-16T15:58:12.522+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2025-03-16T15:58:12.526+09:00 INFO 58817 --- [apiServer] [ restartedMain] o.zerock.apiserver.ApiServerApplication : Started ApiServerApplication in 1.469 seconds (process running for 2.034)
이런 에러가 떠서 테스트를 실행해도 데이터가 정상적으로 저장되지 않습니다 무엇이 원인일까요?
답변 2
0
com.mysql.jdbc.Driver'.
는 조금 오래된 버전이라 더 이상 사용하기를 권장하지 않고 중간에 cj 가 들어간 com.mysql.cj.jdbc.Driver
것을 사용하시기를 권장합니다.
0
안녕하세요, 인프런 AI 인턴입니다.
이동건님께서 겪고 계신 문제는 주로 MySQL JDBC 드라이버 클래스 설정과 관련이 있습니다. 연결 시 경고 메시지와 실행 후 데이터가 정상적으로 저장되지 않는 문제로 볼 때, 다음의 해결 방안을 고려해볼 수 있습니다.
문제의 원인과 해결책
- JDBC 드라이버 클래스명 문제:
- 경고 메시지에서
"Loading class com.mysql.jdbc.Driver'. This is deprecated."으로 나타나듯이,com.mysql.jdbc.Driver는 더 이상 사용되지 않는 클래스명입니다. 최신 MySQL Connector/J 버전에서는com.mysql.cj.jdbc.Driver를 사용해야 합니다.
- 해결 방법:
application.properties파일에서 드라이버 클래스를com.mysql.cj.jdbc.Driver로 수정하세요.
- 경고 메시지에서
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
인트로 데이터베이스 연결 설정 확인:
- 설정이 올바르게 되었는지, 사용자 인증 및 권한 설정이 제대로 되었는지 확인하세요.
- MySQL에서 해당 사용자(
apidbuser)에게 권한이 올바르게 부여되었는지 확인 필요.
- 설정이 올바르게 되었는지, 사용자 인증 및 권한 설정이 제대로 되었는지 확인하세요.
Hibernate 및 JPA 설정:
spring.jpa.open-in-view경고는 Spring Boot의 기본 설정으로, JDBC 연결이 초기화(views에서) 없도록 하려면 해당 옵션을 명시적으로 설정해야 합니다.
- 해결 방법:
application.properties에서spring.jpa.open-in-view=false로 설정하여 이 경고 메시지를 제거할 수 있습니다. 참고로 이 문제는 데이터 저장과 직접 연관된 문제는 아닐 수 있습니다.
관련된 유용한 자료
아래는 비슷한 상황의 질문에 대한 해결책과 방법들입니다:
- 에러가 나지만 작동은합니다.: 스프링 부트에서 데이터소스를 설정할 때 발생할 수 있는 에러와 해결법
- 테이블이 생성되지 않습니다: 데이터베이스 연결 및 설정 관련 문제 해결 사례
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.





