it编程 > 游戏开发 > ar

Sharding-Proxy分库分表的实现方案

24人参与 2025-08-07 ar

一 安装:

https://www.jb51.net/article/237937.htm

二资源

三为什么分库分表

业务越来越大,数据库扛不住啊。

扛不住会怎样呢?数据库性能降低

解决方法:

1 增加mysql硬件资源

2 历史数据归档

3 增加数据库—— 读写分离

4 增加数据库—— 分库分表

5 云数据库tidb

四如何分库分表

1 垂直拆分 -- 微服务化 -- 一个服务一个库

1) 每个库(表)的数据结构一般不同
2) 每个库(表)至少有一个列一样—— 为了join

缺点:
1)数据不均衡。

2 水平拆分--分库分表 -- 数据存的不一样

1)每个库(表)的数据结构都一样
2)双十一订单大,订单一定均分到012库中,解决数据热点问题

缺点:1)扩容的问题,麻烦

3 水平拆分和垂直拆分结合:垂直拆库,水平拆表

五sharding-proxy分库分表实战

1 master建库建表

库:
bookstore_0
bookstore_1
在库中分别建表:
bookinfo_0
bookinfo_1

2 修改config-sharding.yaml

①把mysql驱动jar包复制到lib文件夹下

②config-sharding.yaml

schemaname: bookstore

datasources:
  bookstore_0:
    url: jdbc:mysql://ip:3306/bookstore_0?servertimezone=utc&usessl=false
    username: root
    password: 
    connectiontimeoutmilliseconds: 30000
    idletimeoutmilliseconds: 60000
    maxlifetimemilliseconds: 1800000
    maxpoolsize: 50
  bookstore_1:
    url: jdbc:mysql://ip:3306/bookstore_0?servertimezone=utc&usessl=false
    username: root
    password: 
    connectiontimeoutmilliseconds: 30000
    idletimeoutmilliseconds: 60000
    maxlifetimemilliseconds: 1800000
    maxpoolsize: 50

shardingrule:
  tables:
    bookinfo:
      actualdatanodes: bookstore_${0..1}.bookinfo_${0..1}
      databasestrategy:
        inline:
          shardingcolumn: storeid
          algorithmexpression: bookstore_${storeid % 2}
      tablestrategy:
        inline:
          shardingcolumn: bookid
          algorithmexpression: bookinfo_${bookid % 2}
      #keygenerator:
        #type: snowflake
        #column: order_id

  bindingtables:
    - bookinfo
  defaultdatabasestrategy:
    inline:
      shardingcolumn: storeid
      algorithmexpression: bookstore_${storeid % 2}
  defaulttablestrategy:
    none:

4 进行sql命令操作,只能看到一个库

5 插入数据。sharding-proxy代理端里有数据了

6 连接真正的数据库

这里有个问题:
分库失败,全部写入bookstore_0
分表成功

到此这篇关于sharding-proxy分库分表的文章就介绍到这了,更多相关sharding-proxy分库分表内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

您想发表意见!!点此发布评论

推荐阅读

Apache ShardingSphere简介及使用详解

08-07

解决Failed to get nested archive for entry BOOT-INF/lib/xxx.jar问题

08-06

部分经典机器可惜淘汰! 华为鸿蒙HarmonyOS 5.1版本机型推送系统补丁

08-05

新增三机型升级! 华为鸿蒙 HarmonyOS 6.0.0 (20) Developer Beta2版推送

08-05

解决警告:No archetype found in remote catalog. Defaulting to internal catalog.问题

08-12

NGINX 报错 413 Request Entity Too Large的问题解决

08-13

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论