SpringBoot集成flyway组件步骤流程
在pom文件中添加flyway依赖
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
在pom中添加组件
<!-- 数据库版本管理 -->
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<url>${flyway.db.url}</url>
<user>${flyway.db.user}</user>
<password>${flyway.db.password}</password>
<locations>
<location>${flyway.db.location}</location>
</locations>
<placeholderReplacement>false</placeholderReplacement>
</configuration>
</plugin>
在pom中的配置flyway配置
<properties>
<!-- flyway 数据库版本控制 Oracle start-->
<!-- <flyway.db.url>jdbc:oracle:thin:@127.0.0.1:1521:[服务名]</flyway.db.url>-->
<!-- <flyway.db.user>[用户米]</flyway.db.user>-->
<!-- <flyway.db.password>[密码]</flyway.db.password>-->
<!-- flyway的sql文件路径配置 -->
<!-- <flyway.db.location>classpath:db/migration/oracle</flyway.db.location>-->
<!-- flyway 数据库版本控制 end-->
<!-- flyway 数据库版本控制 MySql start-->
<flyway.db.url>jdbc:mysql://localhost:3306/[数据库名]?serverTimezone=UTC</flyway.db.url>
<flyway.db.user>[用户名]</flyway.db.user>
<flyway.db.password>[密码]</flyway.db.password>
<!-- flyway的sql文件路径配置 -->
<flyway.db.location>classpath:db/migration/mysql</flyway.db.location>
<!-- flyway 数据库版本控制 end-->
</properties>
在db/migration/mysql在创建以V1开头的两个下划线分割"__"的sql文件,默认为1版本
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/88a3fe5a0e579a9105358d4b7e6d5f71.png#pic_center)
在idea中的maven中刷新组件【Plugins】中出现flyway组件
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8281de11f8462fe7541db605e7a3198b.png#pic_center)
点击 flyway:migrate则,flyway会自动去创建库表
点击 flyway:clean 则清空库表(危险!!请谨慎操作!)