Sharding JDBC分表怎么配置
发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,本篇内容介绍了"Sharding JDBC分表怎么配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
千家信息网最后更新 2025年02月04日Sharding JDBC分表怎么配置
本篇内容介绍了"Sharding JDBC分表怎么配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
分表配置
由于的单库分表,所以只配置一个数据源就可以了
#配置数据源spring.shardingsphere.datasource.names=test0#test0spring.shardingsphere.datasource.test0.type=com.zaxxer.hikari.HikariDataSourcespring.shardingsphere.datasource.test0.driver-class-name=com.mysql.cj.jdbc.Driverspring.shardingsphere.datasource.test0.jdbcUrl=jdbc:mysql://127.0.0.1:3306/test0spring.shardingsphere.datasource.test0.username=devadminspring.shardingsphere.datasource.test0.password=
设置绑定表
# 设置绑定表spring.shardingsphere.sharding.binding-tables[0]=health_record,health_task
设置分表的策略
这里根据 record_id 奇偶来分表的。分为 health_record0,health_record1 和 health_task0,health_task1
# health_recordspring.shardingsphere.sharding.tables.health_record.actual-data-nodes=test0.health_record$->{0..1}spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.algorithm-expression=health_record$->{record_id % 2}spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.type=SNOWFLAKE# health_taskspring.shardingsphere.sharding.tables.health_task.actual-data-nodes=test0.health_task$->{0..1}spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.algorithm-expression=health_task$->{record_id %2}spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_task.key-generator.column=task_idspring.shardingsphere.sharding.tables.health_task.key-generator.type=SNOWFLAKE
完整配置
server.port=8080#打印sqlspring.shardingsphere.props.sql.show=true#配置数据源spring.shardingsphere.datasource.names=test0#test0spring.shardingsphere.datasource.test0.type=com.zaxxer.hikari.HikariDataSourcespring.shardingsphere.datasource.test0.driver-class-name=com.mysql.cj.jdbc.Driverspring.shardingsphere.datasource.test0.jdbcUrl=jdbc:mysql://127.0.0.1:3306/test0spring.shardingsphere.datasource.test0.username=devadminspring.shardingsphere.datasource.test0.password=# 设置绑定表spring.shardingsphere.sharding.binding-tables[0]=health_record,health_task# health_recordspring.shardingsphere.sharding.tables.health_record.actual-data-nodes=test0.health_record$->{0..1}spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.algorithm-expression=health_record$->{record_id % 2}spring.shardingsphere.sharding.tables.health_record.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.column=record_idspring.shardingsphere.sharding.tables.health_record.key-generator.type=SNOWFLAKE# health_taskspring.shardingsphere.sharding.tables.health_task.actual-data-nodes=test0.health_task$->{0..1}spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.algorithm-expression=health_task$->{record_id %2}spring.shardingsphere.sharding.tables.health_task.table-strategy.inline.sharding-column=record_idspring.shardingsphere.sharding.tables.health_task.key-generator.column=task_idspring.shardingsphere.sharding.tables.health_task.key-generator.type=SNOWFLAKE
数据库如下
health_level 数据如下
user数据如下
health_record0,health_record1
health_record0 中 record_id 都是偶数 ,health_record1 都是奇数
health_task0,health_task1
health_task0 中 record_id 都是偶数 ,health_task1 都是奇数
"Sharding JDBC分表怎么配置"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
配置
分表
数据
数据源
偶数
内容
奇数
更多
知识
实用
学有所成
接下来
困境
奇偶
实际
情况
数据库
文章
案例
策略
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
长兴软件开发
软件开发国外客户
软件开发男是什么性格
贵州省新爵软件开发有限公司
新建server如何映射数据库
查询出数据库表
安卓系统软件开发学什么
校园 网络安全 尤其
mc服务器自定义商店教程
鄂尔多斯市天气预报软件开发
网络安全前景英文作文
万邦网络安全科技馆
成都软件开发app流程
数据库索引结构种类
女孩读计算机网络技术好吗
互联网科技创业平台
网络安全漫画图片非常漂亮
西安网络安全 4月23日
广州睿达互联网科技
网络安全工作领导机制
魔兽80年代装备数据库
中职计算机网络技术教程
查服务器好坏
网络安全有话说
盐城品牌软件开发哪家好
数据库怎么打印日志文件
用java语言写一个数据库软件
软件开发成本管理系统设计
游戏软件开发是什么行业
软件开发普通本科进华为