技术标签: spring boot java 分库分表 后端
概念介绍、建表SQL参考上文
Spring Boot 2.x 整合 ShardingSphere 5.x 实现分表
本文实现分库分表(采用shardingsphere-jdbc-core-spring-boot-starter 5.0.0正式版)
数据库展示:
SpringBoot工程引入Maven依赖
<!-- ShardingSphere -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.0.0</version>
</dependency>
application.yml配置
spring:
shardingsphere:
# 数据源配置
datasource:
# 数据源名称,多数据源以逗号分隔
names: db0,db1
db0:
# 数据库连接池类名称
type: com.zaxxer.hikari.HikariDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://127.0.0.1:3306/shardingsphere-demo1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
db1:
# 数据库连接池类名称
type: com.zaxxer.hikari.HikariDataSource
# 数据库驱动类名
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://127.0.0.1:3306/shardingsphere-demo2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
# 规则配置
rules:
sharding:
# 分片算法配置
sharding-algorithms:
database-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式(算法自行定义,此处为方便演示效果)
algorithm-expression: db$->{
order_id > 4?1:0}
table-inline:
# 分片算法类型 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/sharding/
type: INLINE
props:
# 分片算法的行表达式
algorithm-expression: t_order$->{
order_id % 4}
# 分布式序列算法配置
key-generators:
snowflake:
# 分布式序列算法(雪花算法:SNOWFLAKE; UUID:UUID)(注:UUID没有props配置) https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/configuration/built-in-algorithm/keygen/
type: SNOWFLAKE
# 分布式序列算法属性配置
props:
# 工作机器唯一标识
worker-id: 1
tables:
# 逻辑表名称
t_order:
# 行表达式标识符可以使用 ${...} 或 $->{...},但前者与 Spring 本身的属性文件占位符冲突,因此在 Spring 环境中使用行表达式标识符建议使用 $->{...}
actual-data-nodes: db${
0..1}.t_order${
0..3}
# 分库策略
database-strategy:
standard:
# 分片列名称
sharding-column: order_id
# 分片算法名称
sharding-algorithm-name: database-inline
# 分表策略
table-strategy:
standard:
# 分片列名称
sharding-column: order_id
# 分片算法名称
sharding-algorithm-name: table-inline
# 属性配置
props:
# 展示修改以后的sql语句
sql-show: true
项目地址(分库分表):https://gitee.com/lemonwjh/ShardingSphere-demo
文章浏览阅读712次,点赞8次,收藏9次。通过将图像切成patch线形层编码成token特征编码的方法,用transformer的encoder来做图像分类multihead和我原有的理解偏差修正。我以为的是QKV会有N块相同的copy(),每一份去做后续的linear等操作。代码里是直接用linear将QKV分为一整个大块,用permute/rearrange的操作切成了N块,f(Q,K)之后再恢复成一整个大块,很强。_vision transformer论文
文章浏览阅读180次。今天在安装好了es,启动和配置花了点时间,这里记录一下。配置elasticsearch.yml,参数大致如下:属性说明cluster.name集群名称,默认elasticsearchnode.name节点名称node.attr.rack节点服务器所在的机架信息path.data索引数据存储路径path.log日志存储路径bootstr..._es安装完
文章浏览阅读1.2k次。【代码】php程序控制打印机自动打印。_php实现打印机打印
文章浏览阅读2.9k次。Frequency Separation for Real-World Super-Resolution[PAPER]_frequency separation for real-world super-resolution
文章浏览阅读6.7k次。本文主要讲述如何使用命令查看虚拟机是否能够联网,及虚拟机的网卡配置。本文主要介绍,如何查看虚拟机网卡,及测试上网功能。_怎么看虚拟机有没有连接到网络
文章浏览阅读3.2k次。导读:在SaaS的经营中,对数据的整理和分析可以帮助我们有效地了解企业经营现状和可能存在的发展机遇。对于企业的不同角色和不同发展阶段,其需要关注的数据指标会有所不同。下面我将根据自己多年从..._支付产品 核心指标
文章浏览阅读1k次。As shown in the image below, the legend is too long for the plot window. what I want to do is:1- To know how to split the legend over a second line?2- To know how to shorten the red line in indicated ..._matlab 图例大小
文章浏览阅读1.4w次,点赞4次,收藏16次。前言matplotlib处理经常能够用到的折线图、柱状图等,还可以画出直方图和密度图。plt.hist()方法matplotlib.pyplot.hist(x,bins = None,range = None,density = None,weights = None,cumulative = False,bottom = None,hist type =‘bar’,align =‘mid’..._将一个数组,绘制成密度图 matplot
文章浏览阅读387次。1.问题给定一个表示分数的非负整数数组。 玩家1从数组任意一端拿取一个分数,随后玩家2继续从剩余数组任意一端拿取分数,然后玩家1拿,……。每次一个玩家只能拿取一个分数,分数被拿取之后不再可取。直到没有剩余分数可取时游戏结束。最终获得分数总和最多的玩家获胜。给定一个表示分数的数组,预测玩家1是否会成为赢家。你可以假设每个玩家的玩法都会使他的分数最大化。力扣(LeetCode)原题链接;2..._486 预测赢家(动态规划)
文章浏览阅读445次,点赞7次,收藏3次。如果你也想学习:黑客&网络安全的SQL攻防知识宝库在此藏,一键关注获宝藏是一种Web应用程序中的安全漏洞,它允许攻击者通过在用户输入中插入恶意的SQL代码,来执行非授权的数据库操作。具体来说,当应用程序将用户输入的数据直接拼接到SQL查询语句中而没有充分验证或转义时,攻击者可以利用这个漏洞来修改原本的查询意图,甚至获取、修改或删除数据库中的数据。SQL注入攻击的原理是用户输入的数据被当成SQL代码执行。_sql注入删除
文章浏览阅读2k次。第一步:下载npm包npm install mxgraph --save第二步:新建一个index.js文件文件内容如下import mx from 'mxgraph';const mxgraph = mx({ mxImageBasePath: './src/images', mxBasePath: './src'});// decode bug https://githu..._vue3.0 ts引入mxgraph
文章浏览阅读1.3k次。我正在为班上的学生写一个简短的程序,最后一部分我还没做完。当我运行这个程序时,所有的函数都会正常工作,直到代码结束,我试图将两个独立函数的成本相乘,以定义另一个函数。我该怎么纠正?下面是完整的代码:def main():wall_space = float(input('Enter amount of wall space in square feet: '))gallon_price = flo..._python计算乘积的函数