当前位置:网站首页>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 :



边栏推荐
- Unreal Engine graphics and text notes: use VAT (vertex animation texture) to make Houdini end on Houdini special effect (ue4/ue5)
- 我希望按照我的思路盡可能將canvas基礎講明白
- Force buckle -104 Maximum depth of binary tree
- Webapi performance optimization
- Basic use and cluster construction of consult
- NFC read / write mode development - book summary
- Jetpack compose layout (III) - custom layout
- [RPC] i/o model - Rector mode of bio, NiO, AIO and NiO
- Free applet making tool, how to make wechat applet
- 链表 删除链表中的节点
猜你喜欢

Learning notes of rxjs takeuntil operator

如何在Microsoft Exchange 2010中安装SSL证书

How to do the wechat selling applet? How to apply for applets

Jetpack compose layout (II) - material components and layout

我希望按照我的思路尽可能将canvas基础讲明白

Redis (II) distributed locks and redis cluster construction

Download the arm64 package of Debian on X86 computer

字符串 实现 strStr()

Jetpack compose layout (III) - custom layout

Houdini图文笔记:Your driver settings have been set to force 4x Antialiasing in OpenGL applications问题的解决
随机推荐
Flutter Gaode map privacy compliance error
Jetpack compose layout (III) - custom layout
How to make small programs on wechat? How to make small programs on wechat
How to do the wechat selling applet? How to apply for applets
Minio基本使用与原理
Webapi performance optimization
Learning notes of rxjs takeuntil operator
Free platform for wechat applet making, steps for wechat applet making
Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
I'm afraid of the goose factory!
How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
The title of my composition is - "my district head father"
单片机开发---基于ESP32-CAM的人脸识别应用
Oracle query comes with JDK version
Methodchannel of flutter
Redis(一)原理与基本使用
Force buckle -104 Maximum depth of binary tree
Yolov5更换上采样方式
Grabcut image segmentation in opencv
Deep understanding of JVM - JVM memory model