当前位置: 代码网 > it编程>游戏开发>ar > Sharding-Proxy分库分表的实现方案

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

2025年08月07日 ar 我要评论
一 安装:https://www.jb51.net/article/237937.htm二资源rolemaster1slave1slave2sharding三为什么分库分表业务越来越大,数据库扛不住啊

一 安装:

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

二资源

  • role
  • master1
  • slave1
  • slave2
  • sharding

三为什么分库分表

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

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

解决方法:

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:
  •  mysql -hip -uroot -p3307 -p     

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

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

6 连接真正的数据库

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

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

(0)

相关文章:

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

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com