今天跟flyway纠缠了一天
报错1:Run项目时就是不启动flyway
我看了这个文章 First Steps - Maven - Flyway - Product Documentation
然后运行:mvn flyway:migrate
报错:Spring-boot Maven flyway Unable to connect to the database. Configure the url, user and passwordSpring-boot Maven flyway 无法连接数据库。配
置url、用户和密码
分析
配置了1)pow.xml,一度想在<build></build>中加flyway,发现大家都没加,坚持不加,也坚持不在里面加账号密码
application.properties中有spring.profiles.active=dev
application-dev.properties中有spring.config.import=optional:file:.env[.properties]
在.env中写了端口号账号密码
2)坚持不把properities换成yaml,这个不可能是原因
3)properties使用了
## spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver ## spring.datasource.url=jdbc:mysql://${MYSQL_HOST}:3306/${DATABASE_NAME}?characterEncoding=UTF8&userSSL=false ## spring.datasource.username=${MYSQL_USER_NAME} ## spring.datasource.password=${MYSQL_PASSWORD}
后来改成以下终于在项目启动时候运行flyway了,并且注意user不是username
spring.flyway.url=jdbc:mysql://${MYSQL_HOST}:3306/${DATABASE_NAME}?characterEncoding=UTF8&userSSL=false spring.flyway.user=${MYSQL_USER_NAME} spring.flyway.password=${MYSQL_PASSWORD}
报错2:flyway Unsupported Database: MySQL 8.0
参见以下cgs1999高手文章,重点是
flyway-core 8.2.1及以后的版本确实是不再支持MySQL。
解决方案
<dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-mysql</artifactId> </dependency>