下载文件,解压文件
http://mirror.bit.edu.cn/apache/incubator/shardingsphere/4.0.0-RC1/apache-shardingsphere-incubating-4.0.0-RC1-sharding-proxy-bin.tar.gz
tar -zxvf apache-shardingsphere-incubating-4.0.0-RC1-sharding-proxy-bin.tar.gz
修改配置文件,分片
cd apache-shardingsphere-incubating-4.0.0-RC1-sharding-proxy-bin/conf
vim config-sharding.yaml
写入以下配置 ,如果多个数据源,文件名字以 config-xxx.yaml这样文件
schemaName: sharding_db # 数据库名字
dataSources:
ds_0: #数据源别名,多个往下边追加
url: jdbc:mysql://127.0.0.1:3306/demo_0?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_1?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
shardingRule: #分库分表的规则
tables: # 多个表就往下边追加
meb_DiscountCoupons: # 逻辑表的名字
actualDataNodes: ds_${0..1}.meb_DiscountCoupons_${0..1} #实际执行的节点
tableStrategy:
inline:
shardingColumn: DiscountID #分表字段
algorithmExpression: meb_DiscountCoupons_${DiscountID % 2} #分表规则
keyGenerator:
type: SNOWFLAKE #分布式主键类型
column: DiscountID # 分布式主键
bindingTables:
- meb_DiscountCoupons # 哪些表需要分库分表
defaultDatabaseStrategy:
inline:
shardingColumn: DisType #分库字段
algorithmExpression: ds_${DisType % 2} #分库算法
defaultTableStrategy:
none:
修改 server.yaml
vim server.yaml
authentication:
username: root
password: root
#
props:
acceptor.size: 16 #用于设置接收客户端请求的工作线程个数,默认为CPU核数*2
sql.show: true # 打印sql
启动 查看日志
cd ../bin
./start.sh
tail -f ../logs/stdout.log
如果报错报缺少驱动jar包,下载jar包
cd ../lib
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.24/mysql-connector-java-5.1.24.jar
配置navicat