flyway : Unsupported Database: MySQL 8.0
Asked Answered
S

4

39

I am using java 11, and I have added flyway in spring-boot application like below.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.29'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.7.0'
    implementation group: 'org.flywaydb', name: 'flyway-core', version: '8.5.13'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

and added properties as

# flyway
spring.flyway.baseline-on-migrate=true
spring.flyway.enabled=false
#spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migration

but it is producing an error that, org.flywaydb.core.api.FlywayException: Unsupported Database: MySQL 8.0

Output

Spirelet answered 22/6, 2022 at 8:5 Comment(0)
R
76

You should add flyway-mysql dependency.

Maven :

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-mysql</artifactId>
</dependency>

Gradel:

dependencies {
    compile "org.flywaydb:flyway-mysql"
}

More information here.

Rebuttal answered 22/6, 2022 at 8:35 Comment(0)
J
7

The only way that worked for me was to add these dependencies to build.gradle:

implementation 'org.flywaydb:flyway-core:8.4.4'
implementation 'org.flywaydb:flyway-mysql:8.4.4'

As shown here

Jiujitsu answered 4/4, 2023 at 8:28 Comment(0)
S
0

For using Flyway you to create a Flayway bean:

Attached exmaple code:

import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayProperties;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(FlywayProperties.class)
public class FlywayDatabaseConfig {

    @Bean(initMethod = "migrate")
    public Flyway flyway(FlywayProperties flywayProperties) {
        return Flyway.configure()
                .dataSource(
                        flywayProperties.getUrl(),
                        flywayProperties.getUser(),
                        flywayProperties.getPassword()
                )
                .locations(flywayProperties.getLocations().toArray(String[]::new))
                .baselineOnMigrate(true)
                .load();
    }

}
Scarbrough answered 28/3 at 6:50 Comment(1)
Answers that contain only code are generally considered poor quality. Can you edit your answer and provide some explanation as to how this code solves the problem described in the posted question?Neurotic
H
0

Using maven, you need:

Step 1: Have mysql dependencies:

      <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
      </dependency>

Step 2: Have flyway-mysql dependencies:

  <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-mysql</artifactId>
    </dependency>

Step 3: Have flyway-core dependencies:

    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>
Hambley answered 12/4 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.