Sharding-Proxy 配置(分库)
1 、创建两个数据库
2 、找到 conf 目录, config-sharding.yaml
schemaName: sharding_db dataSources: ds_0: url: jdbc:mysql://127.0.0.1:3306/edu_db_1?serverTimezone=UTC&useSSL=false username: root password: root connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 ds_1: url: jdbc:mysql://127.0.0.1:3306/edu_db_2?serverTimezone=UTC&useSSL=false username: root password: root connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 50 shardingRule: tables: t_order: actualDataNodes: ds_${0..1}.t_order_${1..2} tableStrategy: inline: shardingColumn: order_id algorithmExpression: t_order_${order_id % 2 + 1} keyGenerator: type: SNOWFLAKE column: order_id bindingTables: t_order defaultDatabaseStrategy: inline: shardingColumn: user_id algorithmExpression: ds_${user_id % 2} defaultTableStrategy: none:
3 、启动 Sharding-Proxy 服务
4 、打开 cmd 仓库,连接 Sharding-Proxy 服务
( 1 )创建数据库表,向表添加记录
( 2 )连接本地 3306 的MySql数据库服务器,表已经创建出来,表里面有数据