ShardingSphere(sharding_jdbc_sharding_proxy)

 

Sharding-jdbc

读写分离

概念

  

  

  

  

   

    sharding-jdbc不做数据同步(数据同步还是由mysql处理)

读写分离实现

MySQL主从实现

  

  

    主库my.ini

    

    从库my.ini

    

    

  

  

  

  

sharding-jdbc读写分离实现  

  application.properties主从配置

  

  

  

  

testcode

  

  

sharding_proxy

简介

  https://shardingsphere.apache.org/document/current/cn/quick-start/shardingsphere-proxy-quick-start/

  透明化的  数据库代理

  理论上支持任何使用 MySQL、PostgreSQL、openGauss 协议的客户端操作数据,对异构语言、运维场景更友好。

  

如何使用

  一个独立应用,需要单独安装部署,进行分库分表/读写分离配置;

  https://shardingsphere.apache.org/document/current/cn/quick-start/shardingsphere-proxy-quick-start/

操作步骤(二进制包为例)

  mysql库此时只有edu_1,没有任何表

    

下载 ShardingSphere-Proxy

  二进制包 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-proxy/startup/bin/

  https://shardingsphere.apache.org/document/current/cn/downloads/

解压二进制包

配置(conf目录)

server.yaml

  去掉注释(authentication和props的注释打开)

  

config-sharding.yaml

  去掉注释(schemaName、dataSources、shardingRules注释打开) 

    如果使用mysql,需要将mysql驱动包引入ext-lib目录

  

  

启动sharding-proxy

  bin/start.sh [port] [/path/to/conf]

  

使用客户端连接 ShardingSphere-Proxy

  mysql -h${proxy_host} -P${proxy_port} -u${proxy_username} -p${proxy_password}

进行sql命令操作

  

sharding-proxy新增表/新增数据

  

  

  

查看mysql数据库表&数据

               

    sharding-proxy会根据策略分表,且 根据策略 插入不同表数据

sharding-proxy实现分库分表 

MySQL中创建多个分库

  

修改conf下的config-sharding.yaml

  

  

启动sharding-proxy服务

  

使用客户端连接 Sharding-Proxy

  mysql -h${proxy_host} -P${proxy_port} -u${proxy_username} -p${proxy_password}

Sharding-Proxy中新建表/新增数据

  

  

MySQL中查看对应的表&数据

  

sharding-proxy实现读写分离

创建3个数据库

  1个master、2个slave(本次都在同一台服务器中部署不同的数据库

  

修改conf下的config-master_slave.yaml配置

  

  

启动sharding-proxy服务

  

Sharding-Proxy中新建表/新增数据

  

  master、slave中创建表

    

  新增数据(不指定数据库),根据读写分离策略,添加到master中数据

            

  查询数据(不指定数据库),在从数据库中查询(由于未配置数据同步,从数据库数据为空)

    

  

posted on   anpeiyong  阅读(57)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示