在咱们的Springboot项目——studentsystem中使用flyway进行数据库版本控制。咱们的springboot项目采用gradle管理。 java
studentsystem项目地址:https://github.com/zjgirl/Spr...
flyway配置参考地址:https://blog.waterstrong.me/f...mysql
配置过程很简单,只须要在build.gradle中添加配置便可:git
//引入配件 plugins { id"org.flywaydb.flyway"version"4.0.3" } //配置flyway properties flyway { url = jdbc:h2:./.tmp/testdb user = sa password = } //添加mysql依赖 dependencies { compilegroup:'mysql',name:'mysql-connector-java',version:'8.0.11' }
flyway默认执行的sql脚本路径是resources/db/migration,.sql脚本以Vx__xxx_xxx_xxx.sql的方式命名。配置完成后,执行./gradlew tasks能够看到可用的命令,执行./gradlew flywayMigrate能够执行sql脚本。github
注意:按理来讲,build项目应该会自动执行flyway,可是咱们这里居然不能自动执行!!!不知道什么缘由。。。。。还有,它没法在非空数据库中迁移表,即便在application.properties中设置了spring.flyway.baseline-on-migrate=true。很奇怪!!!spring
另外,在配置过程当中遇到了一些奇葩的错:sql
一、mysql数据库的密码设置的有问题,报错caching_sha2_password;缘由是在mysql8以前的版本使用的密码加密规则是mysql_native_password,可是在mysql8则是caching_sha2_password,能够重设密码解决:数据库
create user 'root'@'localhost' identified with mysql_native_password by 'your password'; FLUSH PRIVILEGES;
二、‘query_cache_size’的错误:这个是因为依赖的mysql版本太老了,mysql-connector-java的版本仍是6.0.6,须要升级版本到8.0.11 ,这个报错就不存在了。springboot