Chinaunix首页 | 论坛 | 博客
  • 博客访问: 54024
  • 博文数量: 19
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 141
  • 用 户 组: 普通用户
  • 注册时间: 2017-04-01 09:33
文章分类

全部博文(19)

文章存档

2017年(19)

我的朋友

分类: Mysql/postgreSQL

2017-06-22 18:18:07

mysql一主多从,一天发现有两个从库没有同步,其他的又正常,进服务器看,如下。

Seconds_Behind_Master:
越来越大。
Slave_SQL_Running_State:
一直处于Reading event from the relay log 状态


mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.0.0.60
                  Master_User: sync
                  Master_Port: 5506
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000130
          Read_Master_Log_Pos: 334649132
               Relay_Log_File: relay-bin.000066
                Relay_Log_Pos: 75125650
        Relay_Master_Log_File: mysql-bin.000130
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 75125487
              Relay_Log_Space: 334649509
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 7292
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 605506
                  Master_UUID: a8802e96-ed41-11e6-9df7-005056a13bea
             Master_Info_File: /dgg/data/mysql5506/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Reading event from the relay log
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)






如果innodb_flush_log_at_trx_commit设置为0,log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下,在事务提交的时候,不会主动触发写入磁盘的操作。

如果innodb_flush_log_at_trx_commit设置为1,每次事务提交时MySQL都会把log buffer的数据写入log file,并且flush(刷到磁盘)中去.

如果innodb_flush_log_at_trx_commit设置为2,每次事务提交时MySQL都会把log buffer的数据写入log file.但是flush(刷到磁盘)操作并不会同时进行。该模式下,MySQL会每秒执行一次 flush(刷到磁盘)操作。

注意:

由于进程调度策略问题,这个“每秒执行一次 flush(刷到磁盘)操作”并不是保证100%的“每秒”。

sync_binlog

sync_binlog 的默认值是0,像操作系统刷其他文件的机制一样,MySQL不会同步到磁盘中去而是依赖操作系统来刷新binary log。

当sync_binlog =N (N>0) ,MySQL 在每写 N次 二进制日志binary log时,会使用fdatasync()函数将它的写二进制日志binary log同步到磁盘中去。

注意:

如果启用了autocommit,那么每一个语句statement就会有一次写操作;否则每个事务对应一个写操作。

而且mysql服务默认是autocommit打开的

【解决方法】
mysql> set global sync_binlog=20;
Query OK, 0 rows affected (0.00 sec)

mysql> set global innodb_flush_log_at_trx_commit=2;
Query OK, 0 rows affected (0.00 sec)

修改配置文件my.cnf 重启生效。
sync_binlog=20
innodb_flush_log_at_trx_commit=2

原文地址:
阅读(4664) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~