1,首先加入flyway和MySQL的驱动到pom文件,这里一定要注意spring boot和flyway版本的兼容问题,flyway6.0和springboot2.0搭上会出异常
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.4</version>
</dependency>
build的dependency中的版本号对应一致
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<!--整合mysql和flyway-->
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<url>jdbc:mysql://xxx.xx.xx.xx:3306/xxx?characterEncoding=utf-8</url>
<user>username</user>
<password>password</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
</dependencies>
</plugin>
2.建立src/main/resources/db/migration/V2__Add_people.sql文件,并在V2__Add_people.sql中写入要生成的SQL,
其中V+版本号+两个下划线+操作+一个下划线+表名.sql是固定格式
3.使用 mvn flyway:migrate命令创建项目,成功如下。