一、前言
1、版本
apache-shardingsphere-5.0.0-shardingsphere-proxy-bin
二、快速开始
1、配置文件
分表需要配置两个文件(server.yaml、config-sharding.yaml)
server.yaml
rules:- !AUTHORITYusers:- root@%:root- sharding@:shardingprovider:type: ALL_PRIVILEGES_PERMITTED- !TRANSACTIONdefaultType: XAproviderType: Atomikosprops:max-connections-size-per-query: 1kernel-executor-size: 16 # Infinite by default.proxy-frontend-flush-threshold: 128 # The default value is 128.proxy-opentracing-enabled: falseproxy-hint-enabled: falsesql-show: falsecheck-table-metadata-enabled: falseshow-process-list-enabled: false# Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.# The default value is -1, which means set the minimum value for different JDBC drivers.proxy-backend-query-fetch-size: -1check-duplicate-table-enabled: falsesql-comment-parse-enabled: falseproxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.# Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution# if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.proxy-backend-executor-suitable: OLAPproxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.sql-federation-enabled: false
config-sharding.yaml
schemaName: sharding_dbdataSources:ds_0:url: jdbc:mysql://localhost:3306/smiler_user?useUnicode=true&characterEncoding=utf8&serverTimezone=UTCusername: rootpassword: 123456connectionTimeoutMilliseconds: 30000idleTimeoutMilliseconds: 60000maxLifetimeMilliseconds: 1800000maxPoolSize: 50minPoolSize: 1rules:- !SHARDINGtables:smiler_user:actualDataNodes: ds_0.smiler_user_$->{1..2}tableStrategy:standard:shardingColumn: idshardingAlgorithmName: smiler-user-inlineshardingAlgorithms:smiler-user-inline:type: INLINEprops:algorithm-expression: smiler_user_${id % 2 + 1}
2、启动服务

执行如下命令,则可以启动
./start.sh

启动成功后看下输出的日志(在 logs 文件夹中)
端口默认是 3307
3、java 连接 proxy
https://github.com/supkingx/shardingjdbcTest/blob/master/src/main/resources/application.properties
4、客户端连接 proxy


这里不需要使用实际表(smiler_user_1 或者 smiler_user_2),而是可以使用 smiler_user,proxy会自动进行路由分片
