欢迎光临
个人技术文档整理

ShardingSphere-Proxy5.2 分库分表配置

简述

ShardingSphere-Proxy4.0 已经升级到5.0了,但是两者的配置文件还有一定的差别的。
此处讲述的就是ShardingSphere-Proxy 5.2 的落地。概念、分表、分库、分库分表的原理的基本和4.0一样的

1. 环境准备

  • ShardingSphere-Proxy 5.2 下载
官网地址:https://shardingsphere.apache.org/index_zh.html
全版本地址:https://archive.apache.org/dist/shardingsphere/
5.2下载地址:https://www.apache.org/dyn/closer.lua/shardingsphere/5.2.0/apache-shardingsphere-5.2.0-shardingsphere-proxy-bin.tar.gz

  • JDBC数据连接驱动下载
下载地址:https://repo1.maven.org/maven2/mysql/mysql-connector-java/

复制 mysql-connector-java-8.0.29.jar 到 ShardingSphere 的 lib目录中

 

2. 数据库脚本准备

3. 配置 ShardingSphere-Proxy

  • 修改 conf 目录下的 config-sharding.yaml 配置文件:

# 3、创建客户端连接库
schemaName: demo_ds

#1、连接mysql
dataSources:
  hmmsdatasources-0:
    url: jdbc:mysql://localhost:13306/demo_ds_0?serverTimezone=UTC&useSSL=false
    username: root
    password: root
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
    
# 2、分片规则
rules:
- !SHARDING
  tables:
    user: #表名
      actualDataNodes: hmmsdatasources-0.user-${0..1}  #分表规则
      tableStrategy:
        standard:
          shardingColumn: useid   #分片键
          shardingAlgorithmName: use_MOD  #分表算法
  shardingAlgorithms:  #分表算法
    use_MOD:  #取模算法
      type: MOD
      props:
        sharding-count: 2
  • 修改 conf 目录下的 server.yaml 配置文件:

rules:
  - !AUTHORITY
    users:
      - root@%:123456
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED

启动 ShardingSphere-Proxy

双击 Bin目 的  start.bat

 

赞(2)