下載文件,解壓文件
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
寫入以下配置 ,如果多個數(shù)據(jù)源锣吼,文件名字以 config-xxx.yaml這樣文件
schemaName: sharding_db # 數(shù)據(jù)庫名字
dataSources:
ds_0: #數(shù)據(jù)源別名得湘,多個往下邊追加
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: #分庫分表的規(guī)則
tables: # 多個表就往下邊追加
meb_DiscountCoupons: # 邏輯表的名字
actualDataNodes: ds_${0..1}.meb_DiscountCoupons_${0..1} #實際執(zhí)行的節(jié)點
tableStrategy:
inline:
shardingColumn: DiscountID #分表字段
algorithmExpression: meb_DiscountCoupons_${DiscountID % 2} #分表規(guī)則
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 #用于設(shè)置接收客戶端請求的工作線程個數(shù)杖玲,默認為CPU核數(shù)*2
sql.show: true # 打印sql
啟動 查看日志
cd ../bin
./start.sh
tail -f ../logs/stdout.log
如果報錯報缺少驅(qū)動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