강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

백엔드 지망생님의 프로필 이미지
백엔드 지망생

작성한 질문수

flyway가 지정된 데이터베이스에 접근 불가

작성

·

543

·

수정됨

0

스프링부트에서 flyway 데이터베이스 마이그레이션 강의를 보고 있습니다. 옛날 강의라서 강사님은 2.4.5 버전과 flyway 7.x버전을 사용하셨습니다. 일단은 저도 flyway 10.x버전을 사용하려다가 db에 연결이 안되서 7.x버전을 사용하니 성공하여 진도를 나갔습니다. 하지만 test코드 만드는 과정에서 호환문제로 결국 또 막혀서 9.8.1버전을 사용하여 다시하고 있습니다.

build.gradle입니다.

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.2'
    id 'io.spring.dependency-management' version '1.1.6'
    id 'org.flywaydb.flyway' version '9.8.1'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
       languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.flywaydb:flyway-core:9.8.1'
    //runtimeOnly 'com.h2database:h2'
    implementation 'mysql:mysql-connector-java:8.0.32'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
    useJUnitPlatform()
}

flyway {
    url = 'jdbc:mysql://localhost:3306/db_example'
    user = 'sa'
    password = 'password'

    locations = ['classpath:db/migration']
    baselineOnMigrate = true
}

properties입니다.

spring.application.name=bookstore
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=sa
spring.datasource.password=password
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:db/migration

main->resources->db->migration디렉토리에

V1__create_books.sql 파일을 만들었습니다.

CREATE TABLE books(
       id BIGINT NOT NULL,
       name VARCHAR(64),
       author VARCHAR(64)
);

db도 문제 없습니다.



7.x버전으로 했을 때 인텔리제이 터미널에서 ./gradlew flywayMigration 해서
테이블을 만드는 것까지 성공했습니다... 스프링부트3.3.2에 맞는 flyway버전을 사용했더니
계속 실패합니다. 분명 url경로도 맞게 했고 틀린부분이 없을텐데 왜 이럴까요. 디펜던시도

implementation 'org.flywaydb:flyway-core:9.8.1'

implementation 'org.flywaydb:flyway-mysql:9.8.1'
이렇게 바꿔보고 여러짓을 해봤지만 ./gradlew flywayMigration 성공못하고 있습니다..

flyway 9.버전일 때 ./gradlew flywayClean성공하고 ./gradlew flywayMigration실패했는데, db_example을 지우고 다시 생성해서 해보니 ./gradlew flywayClean도 이제 실패합니다.

PS C:\Users\user\OneDrive\Desktop~1-HyunjunLee-56359672\여기 경로 개인사정으로 지웠습니다.\springlecture\bookstore> ./gradlew flywayClean
> Task :flywayClean FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flywayClean'.
> Error occurred while executing flywayClean
  No database found to handle jdbc:mysql://localhost:3306/db_example

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1s
1 actionable task: 1 executed
PS C:\Users\user\OneDrive\Desktop~1-HyunjunLee-56359672\여기 경로 개인사정으로 지웠습니다.\springlecture\bookstore> ./gradlew flywayMigrate 
> Task :flywayMigrate FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flywayMigrate'.
> Error occurred while executing flywayMigrate
  No database found to handle jdbc:mysql://localhost:3306/db_example

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1s
1 actionable task: 1 executed
PS C:\Users\user\OneDrive\Desktop~1-HyunjunLee-56359672\제로베이스\springlecture\bookstore>      

 

이것들은 성공하네요..

PS C:\Users\user\OneDrive\Desktop~1-HyunjunLee-56359672\여기 경로 개인사정으로 지웠습니다.\springlecture\bookstore> ./gradlew clean

BUILD SUCCESSFUL in 1s

1 actionable task: 1 executed

PS C:\Users\user\OneDrive\Desktop~1-HyunjunLee-56359672\여기 경로 개인사정으로 지웠습니다.\springlecture\bookstore> ./gradlew build

BUILD SUCCESSFUL in 3s

7 actionable tasks: 7 executed



답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

Flyway 사용시 발생하는 문제로 접속 정보나 설정이 올바르게 구성되었음에도 불구하고 데이터베이스에 접근할 수 없는 문제를 겪고 계신 것 같습니다. Flyway에서 데이터베이스 접근 실패일 때 고려할 수 있는 사항은 다음과 같습니다.

  1. JDBC URL 형식과 데이터베이스 설정 확인: JDBC URL이 jdbc:mysql://localhost:3306/db_example으로 설정되어 있는데, 이는 MySQL 데이터베이스를 가리키고 있습니다. 사용하시는 데이터베이스 버전 및 JDBC 드라이버 버전이 현재 Flyway 버전과 호환되는지 확인해주세요. MariaDB를 사용 중이라면 JDBC URL 형식이 MySQL과 다를 수 있으므로 확인이 필요합니다.

  2. 사용자 이름과 비밀번호: 데이터베이스 사용자 이름(sa)과 비밀번호(password)가 데이터베이스에 설정된 값과 일치하는지 확인해주세요. 실제 데이터베이스에 설정된 사용자 권한이 충분한지도 검토가 필요합니다.

  3. 데이터베이스 드라이버: mysql:mysql-connector-java:8.0.32 드라이버를 사용 중이신 것으로 보입니다. 이 드라이버가 Flyway 버전 및 MySQL/MariaDB 버전과 호환되는지 확인해보세요.

4.DateTimePicker를 드리지 못해 죄송하지만, Flyway 이슈 해결 시 다음 점검사항을 확인하는 것이 좋습니다:

  • flyway 설정 섹션 내의 url, user, password 설정이 올바른지
  • locations 설정이 마이그레이션 파일 경로를 정확히 가리키고 있는지 (classpath:db/migration)
  • 데이터베이스에 접근할 수 있는 권한이 현재 사용자에게 부여되어있는지
  • 사용 중인 데이터베이스가 MySQL이 맞는지, MariaDB의 경우 JDBC URL이나 설정이 다를 수 있으니 참고해주세요.

스프링 부트 버전과 Flyway 버전 간의 호환성 문제도 있을 수 있으므로, 가능하다면 스프링 부트와 Flyway의 호환성을 고려하여 버전을 선택하는 것이 중요합니다. 이와 더불어, Flyway 공식 문서나 스프링 부트 가이드를 참고하여 설정을 다시 검토해보세요.

더 자세한 도움이나 예제가 필요하다면 Flyway 공식 문서(Flyway Documentation)를 참고하는 것을 추천드립니다.

백엔드 지망생님의 프로필 이미지
백엔드 지망생

작성한 질문수

질문하기