tar -xf apache-shardingsphere-4.1.1-sharding-proxy-bin.tar.gz
mv apache-shardingsphere-4.1.1-sharding-proxy-bin sharding4
cd sharding4/conf
vim server.yaml
==============添加如下配置(注意这个password:root1是sharding登入密码,而不是mysql登入密码)==============
authentication:
users:
root:
password: root1
sharding:
password: sharding
authorizedSchemas: sharding_db
props:
max.connections.size.per.query: 1
acceptor.size: 16 # The default value is available processors count * 2.
executor.size: 16 # Infinite by default.
proxy.frontend.flush.threshold: 128 # The default value is 128.
proxy.transaction.type: LOCAL
proxy.opentracing.enabled: false
proxy.hint.enabled: false
query.with.cipher.column: false
sql.show: false
allow.range.query.with.inline.sharding: true
=========================================
vim config-sharding.yaml
========================新增如下配置(注意这里的password:root123 为数据库密码,)======================
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://192.23.74.194:3306/sharding_test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
username: root
password: root123
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
shardingRule:
tables:
t_order:
actualDataNodes: ds_${0}.t_order_${0..1}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_id
bindingTables:
- t_order
defaultDatabaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: ds_${0}
defaultTableStrategy:
none:
注意:1.同时把mysql驱动拷贝到lib目录下,注意mysql驱动的版本号和url连接 2.要手动创建url后面的数据库
启动服务:
cd sharding4/bin
./start.sh 3307
查看日志:
tail -200f sharding4/logs/stdout.log
最后看到这行:[INFO ] 11:28:58.090 [epollEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2c7904a1, L:/0.0.0.0:3307] ACTIVE
代表启动成功,用Navicat11连接mysql5.7, 不要用Navicat15去连接,否则连接不上
ip:为192.23.74.194 用户名和密码为server.yaml的配置,最后可以连接成功