tmerclub-doc/常见问题及配置/mall4cloud去除分库分表.md
2025-03-19 15:04:57 +08:00

1.8 KiB
Raw Blame History

mall4cloud去除分库分表

目前orderpayment服务使用sharding-jdbc进行分库分表如果需要将其恢复改为单库单表需要做如下操作

  1. 原分表的表结构改为单表结构

  2. nacos中的xxx.yml(相关服务的配置文件) 中的多个数据库配置删除,复制一份单库的配置来替换即可

  3. 更改canal配置

  4. 移除shardingsphere中间件

  5. 注释或者删掉对应服务下mall4cloud-common/mall4cloud-common-sharding-proxy/src/main/java/com/mall4j/cloud/common/sharding/proxy包中的sharding配置类

1. 原分表的表结构改为单表结构

连接shardingsphere中的数据库将对应的分表结构和数据复制到总库中 img_1.jpg

2. 将nacos中的xxx.yml(相关服务的配置文件) 中的数据库连接换成目前mysql的连接地址如下图所示

img_2.jpg

3. 更改canal配置

修改服务器部署 canal/conf/example 目录下的instance.properties

将所有mall4cloud_xxx_[0-9]+.xxx_[0-9]+:* 格式的多库多表数据库配置改为单库单表 mall4cloud_order.order:*

例:将 mall4cloud_order_[0-9]+.order_[0-9]+:* 改为 mall4cloud_order.order:*, 其他数据库的同理

修改完成后重启canal

img_1.png

4. 移除shardingsphere中间件

将mall4cloud-shardingsphere这个中间件删除不部署

5. 注释或者删掉对应服务下mall4cloud-common/mall4cloud-common-sharding-proxy/src/main/java/com/mall4j/cloud/common/sharding/proxy包中的sharding配置类

img_1.png