当前位置:网站首页>Shardingsphere proxy 5.0 sub database and sub table (I)
Shardingsphere proxy 5.0 sub database and sub table (I)
2022-06-25 10:21:00 【@@Mr.Fu】
List of articles
One 、 sketch
- sketch
ShardingSphere-Proxy4.0 Has been upgraded to 5.0 了 , However, there are some differences between the two configuration files , This article is about ShardingSphere-Proxy 5.0 In the fall to the ground . Concept 、 table 、 sub-treasury 、 The basic principle and of sub database and sub table 4.0 Same , Need to know can view https://blog.csdn.net/Fu_Shi_rong/article/details/123541413?spm=1001.2014.3001.5501. - Developer documentation
https://shardingsphere.apache.org/document/current/cn/dev-manual/
Two 、ShardingSphere-Proxy5.0 to ground
Environmental Science
JAVA JDK download
https://pan.baidu.com/s/1A-ksNN0YicT3hXjFscGGwA Extraction code :r9e0JDBC Data connection driven download
https://pan.baidu.com/s/1924iUe7wxGpStAzxxv2K3g Extraction code :jy7zShardingSphere-Proxy 5.0 download 、
https://archive.apache.org/dist/shardingsphere/5.0.0/Window 11
to ground
Conditions
- Real database
- Logical database
- ShardingSphere-Proxy5.0 The configuration file
step
Create a new real database and table 【hmms.user Table as an example 】
Database table structure statement
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `useid` int(11) NOT NULL, `usenam` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' Login name ', `usepwd` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' The login password ', `usestate` int(11) NULL DEFAULT 2 COMMENT '-1: Delete 1: Cancellation 2: normal 3: Report the loss of ', `usekey` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' User secret key ', `usetel` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' User's mobile phone ', `createbyid` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' Add by ', `createbytime` datetime(0) NULL DEFAULT NULL COMMENT ' Add the time ', `modifybyid` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' Modifier ', `modifybytime` datetime(0) NULL DEFAULT NULL COMMENT ' Modification time ', PRIMARY KEY (`useid`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;The operation results are as follows :

modify ShardingSphere-Proxy5.0 The configuration file , And connect
config-sharding.yaml
# 3、 Create client connection Library schemaName: hmms #1、 Connect mysql dataSources: hmmsdatasources-0: url: jdbc:mysql://localhost:3306/hmms?serverTimezone=UTC&useSSL=false username: root password: **** connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 minPoolSize: 1 # 2、 Fragmentation rule rules: - !SHARDING tables: user: # Table name actualDataNodes: hmmsdatasources-0.user-${0..1} # Table rules tableStrategy: standard: shardingColumn: useid # Patch key shardingAlgorithmName: use_MOD # Tabulation algorithm shardingAlgorithms: # Tabulation algorithm use_MOD: # Modular algorithm type: MOD props: sharding-count: 2server.yaml
rules: - !AUTHORITY users: - [email protected]%:***** - [email protected]:sharding provider: type: ALL_PRIVILEGES_PERMITTEDRun the command
# stay ShardingSphere-Proxy bin start.bat Port numberThe operation results are as follows :

Create a new logical data connection , And execute the table structure and data script
The execution results of the logic library are as follows :

Add two pieces of data to the logical database
SQL sentence
INSERT INTO `user` VALUES (1, 'admin', '202CB962AC59075B964B07152D234B70', 2, '123', '123123', 'xiaogang', '2021-08-25 20:12:15', 'xiaogang', NULL); INSERT INTO `user` VALUES (2, 'admin', '202CB962AC59075B964B07152D234B70', 2, '123', '123123', 'xiaogang', '2021-08-25 20:12:15', 'xiaogang', NULL);The results are as follows :


Sub database and sub table
ShardingSphere-Proxy 5.0 To configure# 3、 Create client connection Library schemaName: hmms #1、 Connect mysql dataSources: hmmsdatasources-0: url: jdbc:mysql:// The host address : Port number /hmms-0?serverTimezone=UTC&useSSL=false username: root password: password connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 minPoolSize: 1 hmmsdatasources-1: url: jdbc:mysql:// The host address : Port number /hmms-1?serverTimezone=UTC&useSSL=false username: root password: password connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 minPoolSize: 1 # 2、 Fragmentation rule rules: - !SHARDING tables: user: actualDataNodes: hmmsdatasources-${0..1}.user-${0..1} tableStrategy: standard: shardingColumn: useid shardingAlgorithmName: use_MOD databaseStrategy: # The rules of sub Treasury standard: shardingColumn: useid shardingAlgorithmName: use_MOD keyGenerateStrategy: column: useid keyGeneratorName: snowflake shardingAlgorithms: use_MOD: type: MOD props: sharding-count: 2 use_HASH_MOD: type: HASH_MOD props: sharding-count: '2' keyGenerators: snowflake: type: SNOWFLAKE props: worker-id: 123Sharding algorithm
- Modular algorithm
shardingAlgorithms: # Tabulation algorithm use_MOD: # Modular algorithm type: MOD props: sharding-count: 2 # The split table data and the expression of the split table must be consistent
Range algorithm
shardingAlgorithms: use_BOUNDARY_RANGE: type: BOUNDARY_RANGE props: sharding-ranges: 2,100 # Multiple nodes are separated by commas [ The node is configured according to the sub table ] # remarks # The partition key is :useid int type # The sub table is 3 Tables #sharding-ranges: 2,100 In order to 2 For the node , Less than 2 Save the data to the table 0,2 To 99 Save to table 1,100 Save the above to the table 3Capacity algorithm
shardingAlgorithms: use_VOLUME_RANGE: type: VOLUME_RANGE props: range-lower: '20000000' # minimum value range-upper: '40000000' # Maximum # Interval of segmented interval data sharding-volume: '20000000' # remarks The minimum value is 2000 ten thousand , In other words, the amount of table data is less than or equal to 2000 ten thousand , The maximum quantity is 4000 ten thousand The interval between tables is 2000 ten thousand For example, there are two tables : 1-2000 ten thousand Save to table 0 2001 ten thousand -4000 ten thousand Save to table 1 The maximum value is defined according to the number of sub tables Divided into three tables , The maximum value is 6000 ten thousandHASH-CODE Algorithm 【 If the fragment key is a string type , Need this algorithm to divide the table 】
shardingAlgorithms: use_HASH_MOD: type: HASH_MOD props: sharding-count: '2' # Number of tables , Single quotation marks must be addedAccording to the time table algorithm
shardingAlgorithms: use_AUTO_INTERVAL: type: AUTO_INTERVAL props: datetime-lower: '2020-01-01 23:59:59' datetime-upper: '2022-12-31 23:59:59' # With 1 Divided by year sharding-seconds: '31536000' # With 1 Divided into months #sharding-seconds: '2678400' # With 1 Divided in days #sharding-seconds: '86400' # The maximum value set must match the score table , No one reported wrong. , Table not found
Distributed ID
config-sharding.yaml
# 3、 Create client connection Library schemaName: hmms #1、 Connect mysql dataSources: hmmsdatasources-0: url: jdbc:mysql://localhost:3306/hmms?serverTimezone=UTC&useSSL=false username: root password: 1QAZ2WSX3EDC connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 minPoolSize: 1 # 2、 Fragmentation rule rules: - !SHARDING tables: user: actualDataNodes: hmmsdatasources-0.user-${0..1} tableStrategy: standard: shardingColumn: id shardingAlgorithmName: use_HASH_MOD keyGenerateStrategy: column: id keyGeneratorName: snowflake shardingAlgorithms: use_MOD: type: MOD props: sharding-count: 2 use_HASH_MOD: type: HASH_MOD props: sharding-count: '2' keyGenerators: snowflake: type: SNOWFLAKE props: worker-id: 123Table structure sql sentence
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for user -- ---------------------------- DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` varchar(100), `useid` int(11) NOT NULL, `usenam` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' Login name ', `usepwd` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' The login password ', `usestate` int(11) NULL DEFAULT 2 COMMENT '-1: Delete 1: Cancellation 2: normal 3: Report the loss of ', `usekey` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' User secret key ', `usetel` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' User's mobile phone ', `createbyid` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' Add by ', `createbytime` datetime(0) NULL DEFAULT NULL COMMENT ' Add the time ', `modifybyid` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' Modifier ', `modifybytime` datetime(0) NULL DEFAULT NULL COMMENT ' Modification time ', PRIMARY KEY (`useid`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1;Data filling statement
INSERT INTO `user`(useid,usenam,usepwd,usestate,usekey,usetel,createbyid,createbytime,modifybyid,modifybytime) VALUES (1, 'admin', '202CB962AC59075B964B07152D234B70', 2, '123', '123123', 'xiaogang', '2021-08-25 20:12:15', 'xiaogang', NULL);The execution structure is as follows :



边栏推荐
- How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
- WPF 绑定表达式和绑定数据源(一)
- DigiCert和GlobalSign单域名OV SSL证书对比评测
- The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores
- Solutions using protobuf in TS projects
- ScheduleMaster分布式任务调度中心基本使用和原理
- 网络协议学习---LLDP协议学习
- View. post VS Handler. Differences and usage scenarios of post
- JS tool function, self encapsulating a throttling function
- How to install SSL certificates in Microsoft Exchange 2010
猜你喜欢

ShardingSphere-Proxy 4.1 分库分表

链表 删除链表中的节点

【OpenCV 例程200篇】210. 绘制直线也会有这么多坑?

Mqtt beginner level chapter

Linked list delete nodes in the linked list

Flask blog practice - realize the latest articles and search in the sidebar

Free platform for wechat applet making, steps for wechat applet making

我的作文题目是——《我的区长父亲》
![[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world](/img/f7/b3239802d19d00f760bb3174649a89.jpg)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world

Learning notes of rxjs takeuntil operator
随机推荐
Comparison and evaluation of digicert and globalsign single domain ov SSL certificates
View. post VS Handler. Differences and usage scenarios of post
MongoDB的原理、基本使用、集群和分片集群
Kotlin keyword and operator
Etcd tutorial - Chapter 4 etcd cluster security configuration
[dynamic planning] - Digital triangle
ShardingSphere-Proxy 4.1 分庫分錶
Guiding principle - read source code
Oracle query comes with JDK version
Redis(二)分布式锁与Redis集群搭建
The path of Architects
Basic use and principle of Minio
Free platform for wechat applet making, steps for wechat applet making
How to make small programs on wechat? How to make small programs on wechat
The real difference between i++ and ++i
WPF Prism框架
Bug- solve the display length limitation of log distinguished character encoding (edittext+lengthfilter)
Principle of distribution: understanding the gossip protocol
Jetpack compose layout (IV) - constraintlayout
【论文阅读|深读】DRNE:Deep Recursive Network Embedding with Regular Equivalence