springboot mysql/mariadb迁移成oceanbase
前言:项目架构为 springboot+mybatis-plus+mysql
1.部署oceanbase服务
2.springboot项目引入oceanbase依赖(即ob驱动)
ps:删除原有的mysql/mariadb依赖
<dependency>
<groupId>com.oceanbase</groupId>
<artifactId>oceanbase-client</artifactId>
<version>2.4.14</version>
</dependency>
3.修改springboot项目数据库配置
url: jdbc:oceanbase://ip:端口/scheme名
username: 用户名@租户名#集群名 或者 集群名:租户名:用户名
password: 密码
driver-class-name: com.oceanbase.jdbc.Driver
ps:这里可以使用mysql驱动和协议,因为oceanbase兼容mysql协议,但不推荐。
如果使用的是druid链接池,需要指定druid防火墙的类型:
filters: stat,slf4j
如果是多数据源,建议使用hikari,因为druid不兼容oceanbase
4.升级mybatis-plus版本
4.1升级mybatis-plus版本
如果项目mybatis-plus版本低于3.5.2.*,需要升级,我这里升级为3.5.3.1
因为低版本的mybatis-plus不兼容oceanbase,即低版本的Dbtype.calss中缺少oceanbase枚举值,即下图标红的内容:
4.2 修改MybatisPlusConfig类
高版本Mybatis-plus的分页依赖于PaginationInnerInterceptor插件 ,低版本是PaginationInterceptor类。如下图: