瑞吉外卖项目优化篇总结-MySql主从复制的实现

4、使用了Mysql读写分离技术

若报错,说明从库目前线程被占用

使用stop slabe停掉

错误解决:

Master Slave 主从同步错误

Slave_IO_Running:NO

Slave_SQL_Running:Yes

#在Slave库上查看状态

mysql> show slave status\G

Slave_IO_Running: No

Slave_SQL_Running: Yes

#重启master库:service mysqld restart

mysql> show master status;

+------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------------+--------------+--------------+------------------+

| mysql-bin.000534 | 14670663 | | |

+------------------------+--------------+--------------+------------------+

mysql> stop slave;

mysql> change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=98;

mysql> start slave;

mysql> show slave status\G

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

使用sharding-JDBC方便实现数据库读写分离

参考配置文件:

rw_dwmo的yml配置文件:

server:
  port: 8080
mybatis-plus:
  configuration:
    #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射    
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      id-type: ASSIGN_ID
spring:
  shardingsphere:
    datasource:
      names:
        master,slave
      # 主数据源     
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.85.128:3306/rw?characterEncoding=utf-8
        username: root
        password: root
      # 从数据源      
      slave:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.85.12:339rw?characterEncoding=utf-8
        username: root
        password: root
    masterslave:
      # 读写分离配置      
      load-balance-algorithm-type: round_robin #轮询  设置从库数据库负载均衡,例如查询操作时,若有多个从库可轮训发送查找请求,类似nginx   
      # 最终的数据源名称      
      name: dataSource
      # 主库数据源名称      
      master-data-source-name: master
      # 从库数据源名称列表,多个逗号分隔      
      slave-data-source-names: slave
    props:
      sql:
        show: true #开启SQL显示,默认false  main:
    allow-bean-definition-overriding: true

瑞吉外卖代码改造:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值