当前位置:网站首页>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 :r9e0
JDBC Data connection driven download
https://pan.baidu.com/s/1924iUe7wxGpStAzxxv2K3g Extraction code :jy7z
ShardingSphere-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: 2
server.yaml
rules: - !AUTHORITY users: - [email protected]%:***** - [email protected]:sharding provider: type: ALL_PRIVILEGES_PERMITTED
Run the command
# stay ShardingSphere-Proxy bin start.bat Port number
The 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: 123
Sharding 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 3
Capacity 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 thousand
HASH-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 added
According 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: 123
Table 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 :
边栏推荐
- Redis (I) principle and basic use
- ShardingSphere-Proxy 5.0 分库分表(一)
- Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
- Wearable devices may reveal personal privacy
- 虚幻引擎图文笔记:使用VAT(Vertex Aniamtion Texture)制作破碎特效(Houdini,UE4/UE5)上 Houdini端
- Gradle download warehouse is slow
- Mqtt beginner level chapter
- 依赖属性、依赖附加属性以及类型转换
- Flutter Gaode map privacy compliance error
- How to install SSL certificates in Microsoft Exchange 2010
猜你喜欢
Request&Response有这一篇就够了
什么是 CRA
ShardingSphere-Proxy 5.0 分库分表(一)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
Etcd tutorial - Chapter 4 etcd cluster security configuration
Flask blog practice - realize the latest articles and search in the sidebar
Shardingsphere proxy 4.1 sub database and sub table
【OpenCV 例程200篇】210. 绘制直线也会有这么多坑?
【动态规划】—— 数字三角形
【论文阅读|深度】Role-based network embedding via structural features reconstruction with degree-regularized
随机推荐
Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
宏的运用接续符\
Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
WPF 绑定表达式和绑定数据源(一)
Tiktok brand goes to sea: both exposure and transformation are required. What are the skills of information flow advertising?
Grabcut image segmentation in opencv
i++ 和 ++i的真正区别
Difference between malloc and calloc
单片机开发---基于ESP32-CAM的人脸识别应用
如何在Microsoft Exchange 2010中安装SSL证书
[paper reading | deep reading] drne:deep recursive network embedding with regular equivalence
Repo sync will automatically switch the correspondence between the local branch and the remote branch - how to customize this behavior
Guiding principle - read source code
Jetpack compose layout (III) - custom layout
Floating window --- create an activity floating window (can be dragged)
DigiCert和GlobalSign单域名OV SSL证书对比评测
Android database security: after the user exits, the transaction rollback log still stores relevant data information
Basic usage and principle of schedulemaster distributed task scheduling center
manhattan_ Slam environment configuration
New school: no fraud Economics