Access denied for user 'root'@'localhost' (using password: YES)

2024. 9. 26. 00:20· Project/문제 & 해결
목차
  1. 문제 상황
  2. 환경
  3. 로그
  4. 해결 방법

문제 상황

처음에 프로젝트 설정 시에는 DB(MySQL) 연결이 정상적으로 된 것을 확인했지만, 엔티티를 작성한 후 다시 실행했을 때는, DB 연결이 정상적으로 되지 않았다.

환경

  • Spring Boot 3.3.4
  • MySQL 8.0.34

로그

2024-09-20T16:23:06.654+09:00  WARN 83120 --- [  restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata

java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)" because the return value of "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.sqlExceptionHelper()" is null
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:116) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
	...
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.3.jar:3.3.3]

2024-09-20T16:23:06.672+09:00  WARN 83120 --- [  restartedMain] org.hibernate.orm.deprecation            : HHH90000025: MySQL8Dialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
2024-09-20T16:23:06.673+09:00  WARN 83120 --- [  restartedMain] org.hibernate.orm.deprecation            : HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
2024-09-20T16:23:07.061+09:00  INFO 83120 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: drop table if exists users
2024-09-20T16:23:07.067+09:00  INFO 83120 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-09-20T16:23:08.086+09:00  WARN 83120 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1045, SQLState: 28000
2024-09-20T16:23:08.086+09:00 ERROR 83120 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : Access denied for user 'root'@'localhost' (using password: YES)
2024-09-20T16:23:08.091+09:00 ERROR 83120 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [Access denied for user 'root'@'localhost' (using password: YES)] [n/a]
2024-09-20T16:23:08.092+09:00  WARN 83120 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [Access denied for user 'root'@'localhost' (using password: YES)] [n/a]
2024-09-20T16:23:08.093+09:00  INFO 83120 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2024-09-20T16:23:08.103+09:00  INFO 83120 --- [  restartedMain] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-09-20T16:23:08.114+09:00 ERROR 83120 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [Access denied for user 'root'@'localhost' (using password: YES)] [n/a]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1806) ~[spring-beans-6.1.12.jar:6.1.12]
	...
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.3.jar:3.3.3]
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [Access denied for user 'root'@'localhost' (using password: YES)] [n/a]
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421) ~[spring-orm-6.1.12.jar:6.1.12]
	... 20 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [Access denied for user 'root'@'localhost' (using password: YES)] [n/a]
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:63) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
	... 24 common frames omitted
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	... 47 common frames omitted


Process finished with exit code 0

해결 방법

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/{dbname}
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: '0000'

password를 '(따옴표)로 감싸서 문자열로 넘긴다.

728x90

'Project > 문제 & 해결' 카테고리의 다른 글

Github Secret으로 yml 파일 관리 및 깃허브에서 삭제  (1) 2024.08.20
  1. 문제 상황
  2. 환경
  3. 로그
  4. 해결 방법
'Project/문제 & 해결' 카테고리의 다른 글
  • Github Secret으로 yml 파일 관리 및 깃허브에서 삭제
kyung.Kh
kyung.Kh
Dev..studynotekyung.Kh 님의 블로그입니다.
kyung.Kh
Dev..studynote
kyung.Kh
전체
오늘
어제
06-11 02:20
  • 분류 전체보기 (75)
    • Algorithm PS (32)
      • Baekjoon Online Judge (32)
      • Programmers (0)
    • Computer Science (8)
      • Databse (2)
      • Operating System (1)
      • Computer Network (0)
      • Computer Architecture (0)
      • Algorithm (4)
      • Java & Spring (1)
    • Spring (29)
      • Spring Boot (1)
      • 스프링 핵심 원리 - 기본편(인프런 김영한) (7)
      • Java (1)
      • 자바 ORM 표준 JPA 프로그래밍 (20)
    • Project (2)
      • 문제 & 해결 (2)
    • Book (3)
      • 객체지향의 사실과 오해 (3)
    • 우하한테크코스 (1)
      • precourse (1)

최근 글

인기 글

블로그 메뉴

    태그

    • dfs
    • springboot
    • 스프링 기본편
    • 스프링 김영한
    • BFS
    • Union-Find
    • Graph
    • 스프링부트
    • Spring
    • 구현
    • DP
    • 인프런
    • 객체지향
    • 그리디
    • JPA
    • 백준
    • 스프링
    • 해시를 사용한 집합과 맵
    • 재귀
    • 알고리즘
    hELLO · Designed By 정상우.v4.2.2
    kyung.Kh
    Access denied for user 'root'@'localhost' (using password: YES)
    상단으로

    티스토리툴바

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.