spring boot整合flyway---MYSQL

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命令创建项目,成功如下。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值