• sharding-jdbc读写分离


    sharding-jdbc读写分离

    为了解决数据库的性能问题。前提条件是数据库同步。
    导包:

            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druidartifactId>
                <version>1.1.22version>
            dependency>
    
            
            <dependency>
                <groupId>org.apache.shardingspheregroupId>
                <artifactId>sharding-jdbc-spring-boot-starterartifactId>
                <version>4.0.0-RC1version>
            dependency>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    配置文件

    
      # 3.sharding-jdbc读写分离
      shardingsphere:
        # 数据源配置
        datasource:
          names: master,slave1,slave2
          # master数据源
          master:
            type: com.alibaba.druid.pool.DruidDataSource
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://xxx:3306/bks_user?serverTimezone=UTC?useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf-8
            username: root
            password: xxx
          # slave1数据源
          slave1:
            type: com.alibaba.druid.pool.DruidDataSource
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://xxx:3306/bks_user?serverTimezone=UTC?useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf-8
            username: root
            password: xxx
          # slave2数据源
          slave2:
            type: com.alibaba.druid.pool.DruidDataSource
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://xxx:3306/bks_user?serverTimezone=UTC?useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&characterEncoding=utf-8
            username: root
            password: xxx
        # 读写分离配置
        masterslave:
          # 从库负载均衡类型:随机
          load-balance-algorithm-type: round_robin
          name: ms
          master-data-source-name: master
          slave-data-source-names: slave1,slave2
        # 显示SQL
        props:
          sql:
            show: true
    
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
  • 相关阅读:
    netty应用实践
    11.数组的分类和定义
    开发神技!阿里消息中间件进阶手册限时开源,请接住我的下巴
    vue 监听dom元素尺寸大小改变
    uniapp 跳转到指定位置
    Android 12(S) 图像显示系统 - BufferQueue的工作流程(十)
    软件供应链安全:如何防范潜在的攻击?
    Vue项目配置文件整理
    java基于ssm+vue高校人事管理系统
    技术人员应该使用那种搜索引擎?
  • 原文地址:https://blog.csdn.net/L1569850979/article/details/126097882