好网站建设公司哪家好,广州比较好的网站建设公司,wordpress 可以上传存储附件,中国十大物联网公司前言 ShardingSphere可以支撑分库分表#xff0c;刚果商城采用了垂直分库#xff08;根据不同业务拆分数据库#xff09;#xff0c;因此此文章只演示水平分表。 垂直分库
不同业务拆分为不同的数据库#xff08;例如商城业务#xff09; 水平分表 分表可以通过将大表拆…前言 ShardingSphere可以支撑分库分表刚果商城采用了垂直分库根据不同业务拆分数据库因此此文章只演示水平分表。 垂直分库
不同业务拆分为不同的数据库例如商城业务 水平分表 分表可以通过将大表拆分为多个小表减少单表的数据量从而提高查询性能。好处比较多… 分表命名格式最好为逻辑表_num这个格式方便后续操作 介绍完基本的概念开始实践。
ShardingSphere官方文档
接下来重点关注分片算法和加密算法 核心依赖
我这里使用的是5.2.0版本 dependencygroupIdorg.apache.shardingsphere/groupIdartifactIdshardingsphere-jdbc-core-spring-boot-starter/artifactIdversion5.2.0/version/dependency配置文件核心
spring:shardingsphere:datasource:# 为每个数据源进行配置有几个配几个ds-0:driver-class-name: com.mysql.jdbc.Drivertype: com.zaxxer.hikari.HikariDataSource# 配置数据源可以配置多个names: ds-0props:# 打印sql日志方便观察sql-show: truemax-connections-size-per-query: 10rules:encrypt:encryptors:# 自定义加密算法名称customer-user-encryptor:props:# AES 使用的 KEYaes-key-value: ADbisulBtxnnKFoWtype: AEStables:# 指定表相应字段加密算法customer_user:# 加密字段columns:mail:cipher-column: mailencryptor-name: customer-user-encryptorphone:cipher-column: phoneencryptor-name: customer-user-encryptorreceive_address:columns:phone:cipher-column: phoneencryptor-name: customer-user-encryptordetail_address:cipher-column: detail_addressencryptor-name: customer-user-encryptorsharding:sharding-algorithms:# 自定义分片算法名称 哈希取模分片算法 对 16 取余sharding_by_mod:props:sharding-count: 16type: HASH_MOD # hash算法tables:# 不同表配置分片算法customer_user:# 指定真实表表名称 $-{0..15} 即 0-15actual-data-nodes: ds-0.customer_user_$-{0..15}table-strategy:standard:sharding-algorithm-name: sharding_by_modsharding-column: id # 分片字段operation_log:actual-data-nodes: ds-0.operation_log_$-{0..15}table-strategy:standard:sharding-algorithm-name: sharding_by_modsharding-column: customer_user_idreceive_address:actual-data-nodes: ds-0.receive_address_$-{0..15}table-strategy:standard:sharding-algorithm-name: sharding_by_modsharding-column: customer_user_id分片算法 加密算法 代码实践
配置完之后使用起来就很简单了只需将实体类指定逻辑表名称使用起来是无感知的。 测试一下
调用【新增用户】接口。
入参 执行时会发现有个逻辑SQL和实际SQL可以看到当前用户通过配置的Hash分片算法被分配到了customer_user_5表中 同时加密算法也起了作用phone和mail字段都被加密。 ShardingSphere使用起来就是这么滴简单。 希望这篇文章对大家有帮助有什么错误可以联系私信博主改正。 欢迎大家点赞 收藏 关注。关注小李不迷路~ 详细分库分表内容可以看我这篇博客 MySQL与分布式