当前位置:网站首页>分库分表之sharding-proxy
分库分表之sharding-proxy
2022-08-11 05:12:00 【导演1995】
一、环境介绍
- windows10
- mysql 版本8.0.16
- sharding-proxy版本5.0.0 :https://archive.apache.org/dist/shardingsphere/5.0.0/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin.tar.gz
二、安装
- 将shardingsphere解压,保证lib中的jar包文件名称完整,同时下载mysql-connection-java-8.0.16 jar包放到lib目录下,修改conf中的server.yaml 和 config-sharding.yaml
rules:
- !AUTHORITY
users:
- [email protected]%:xrq123
- [email protected]:sharding
provider:
type: ALL_PRIVILEGES_PERMITTED
- !TRANSACTION
defaultType: XA
providerType: Atomikos
props:
max-connections-size-per-query: 1
kernel-executor-size: 16 # Infinite by default.
proxy-frontend-flush-threshold: 128 # The default value is 128.
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
check-table-metadata-enabled: false
show-process-list-enabled: false
# Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
# The default value is -1, which means set the minimum value for different JDBC drivers.
proxy-backend-query-fetch-size: -1
check-duplicate-table-enabled: false
sql-comment-parse-enabled: false
proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
# Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
# if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
proxy-backend-executor-suitable: OLAP
proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
sql-federation-enabled: false
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
username: root
password: xrq123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
username: root
password: xrq123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
t_order_item:
actualDataNodes: ds_${0..1}.t_order_item_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_item_inline
keyGenerateStrategy:
column: order_item_id
keyGeneratorName: snowflake
bindingTables:
- t_order,t_order_item
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
t_order_item_inline:
type: INLINE
props:
algorithm-expression: t_order_item_${order_id % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
这里使用的分片算法是行表达式分片算法 INLINE,分片键即主键。如果分片键是非主键,取模的话,可以用MOD分片算法,增加属性值sharding-count
分片算法参考链接:
三、启动
- 新建demo_ds_0、demo_ds_1数据库
- 进入bin目录 ,cmd 执行start.bat 3316
- 新启动一个cmd执行命令
mysql -h 127.0.0.1 -P 3316 -uroot -pxrq123 -A
show schemas; use sharding_db;
CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id));
insert into t_order(user_id,status) values(1,'ok'),(2,'fail'),(3,'hello world'),(4,'2022-04-21'),(5,'Hangzhou king of volume'),(6,'In learning sub - library sub - table');
mysql> select * from t_order; +--------------------+---------+---------------------------------------+ | order_id | user_id | status | +--------------------+---------+---------------------------------------+ | 742032272861409280 | 1 | ok | | 742032272861409281 | 2 | fail | | 742032272861409282 | 3 | hello world | | 742032272861409283 | 4 | 2022-04-21 | | 742032272861409284 | 5 | Hangzhou king of volume | | 742032272861409285 | 6 | In learning sub - library sub - table | +--------------------+---------+---------------------------------------+
- 在两个数据库中分别可以看见t_order_0、t_order_1表,数据如下:
如果对大家有帮助的话,点赞支持哈,欢迎批评指正,相互交流!
边栏推荐
- 2022煤矿瓦斯检查考试题模拟考试题库及答案
- Golden Warehouse Database KingbaseGIS User Manual (6.8. Geometry Object Input Function)
- 智能指针笔记
- shell 脚本编程---入门
- Idea essential skills to improve work efficiency
- 2022年质量员-土建方向-通用基础(质量员)考试模拟100题及在线模拟考试
- [ARM] rk3399 mounts nfs error
- 应用层协议——DNS
- 【嵌入式开源库】MultiTimer 的使用,一款可无限扩展的软件定时器
- Paper Notes: BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
猜你喜欢
交换机和路由器技术-22/23-OSPF动态路由协议/链路状态同步过程
Switch and Router Technology-33-Static NAT
论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
论文笔记:BBN: Bilateral-Branch Network with Cumulative Learningfor Long-Tailed Visual Recognition
四大函数式接口
Idea essential skills to improve work efficiency
Idea 2021.3.3版本文件目录展开
MySQL必知必会(初级篇)
Idea提升工作效率的必备技巧
【ARM】rk3399挂载nfs报错
随机推荐
2022 Quality Officer-Civil Construction Direction-General Basic (Quality Officer) Exam Mock 100 Questions and Online Mock Exam
开发工具篇第七讲:阿里云日志查询与分析
论文笔记:Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
【嵌入式开源库】使用J-Link打印日志,让你节省一个打印串口
2021年网络规划设计师下午案例题
In the closing pages/uninstall (unload) sends a request to the server before the document
代理模式(简要介绍)
[Untitled] 2022 Amination Process Exam Questions Mock Exam Question Bank and Online Mock Exam
oracle表空间与用户的创建
Project Practice Lecture 27: Application of Status Mode in Duplicate Brands
Day38 LeetCode
【嵌入式开源库】cJSON的使用,高效精简的json解析库
Switch and Router Technology-33-Static NAT
Thymeleaf
nodes服务器
shell 脚本编程---入门
Paper Notes: Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks
Switch and Router Technology - 32 - Named ACL
用白嫖的Adobe正版软件,减少应届毕业生的慢就业、不就业等现象
代码在线审查(添加网页批注)的实现