日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql relay log时间_如何得到Slave应用relay-log的时间

發布時間:2023/12/19 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql relay log时间_如何得到Slave应用relay-log的时间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官方社區版MySQL 5.7.19 基于Row+Position搭建的一主一從異步復制結構:Master->{Slave}

ROLE

HOSTNAME

BASEDIR

DATADIR

IP

PORT

Master

ZST1

/usr/local/mysql

/data/mysql/mysql3307/data

192.168.85.132

3307

Slave

ZST2

/usr/local/mysql

/data/mysql/mysql3307/data

192.168.85.133

3307

最初是想核實延遲復制的master_delay=N以哪個時間作為基準計算,想到如果在Slave的表中添加一個以current_timestamp為默認值的時間列,從庫在應用relay-log時將"當前"時間寫入。將它和表中原來的時間字段作對比,就可以知道延遲時間。想法貌似不錯,但...自以為是...很悲催~

# 測試表結構

mydba@192.168.85.133,3307 [replcrash]> show create tablepy_user;+---------+----------------------------------------------+

| Table | Create Table |

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

| py_user | CREATE TABLE`py_user` (

`uid`int(11) NOT NULLAUTO_INCREMENT,

`name`varchar(32) DEFAULT NULL,

`add_time`datetime DEFAULT CURRENT_TIMESTAMP,

`server_id`varchar(10) DEFAULT NULL,PRIMARY KEY(`uid`)

) ENGINE=InnoDB AUTO_INCREMENT=4105 DEFAULT CHARSET=utf8 |

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

1 row in set (0.00sec)

# Slave開啟延遲復制

mydba@192.168.85.133,3307 [replcrash]> change master to master_delay = 30;

# 添加參考列

mydba@192.168.85.133,3307 [replcrash]> alter table py_user add ins_time datetime default current_timestamp;

View Code

然后往Master寫入新數據,并到Slave查看數據

# Slave數據

mydba@192.168.85.133,3307 [replcrash]> select * frompy_user;+-----+--------------------------+---------------------+-----------+---------------------+

| uid | name | add_time | server_id | ins_time |

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

| 1 | BD9U7I9W68BTDIXWEEUQNYRX | 2017-12-19 11:07:40 | 1323307 | 2017-12-19 11:07:40 |

| 2 | 9722XBCKISXDBSRDA5VA0A | 2017-12-19 11:07:42 | 1323307 | 2017-12-19 11:07:42 |

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

2 rows in set (0.00sec)

# general-log

[root@ZST2 data]# cat mysql-general.log

/usr/local/mysql/bin/mysqld, Version: 5.7.19-log (MySQL Community Server (GPL)). started with:

Tcp port:3307 Unix socket: /tmp/mysql3307.sock

Time Id Command Argument

...2017-12-19T03:07:46.515218Z 17 Query truncate tablepy_user2017-12-19T03:08:10.516900Z 17 Query BEGIN

2017-12-19T03:08:10.517318Z 17 Query COMMIT /*implicit, from Xid_log_event*/

2017-12-19T03:08:12.517930Z 17 Query BEGIN

2017-12-19T03:08:12.518383Z 17 Query COMMIT /*implicit, from Xid_log_event*/

2017-12-19T03:08:27.614844Z 3 Query select * frompy_user[root@ZST2 data]#

View Code

general-log可以看出Slave確實是晚于Master 30秒才應用,但新寫入的記錄對應的ins_time并沒有滯后add_time 30秒

為什么會出現這種情況?解析relay-log查看日志中是如何記錄的

# Slave上的relay-log信息

[root@ZST2 data]# mysqlbinlog-v -vv --base64-output=decode-rows relay-bin.000009...

# at2803#171219 11:07:42 server id 1323307 end_log_pos 19664 CRC32 0x6fdfa523 Query thread_id=26 exec_time=0 error_code=0SET TIMESTAMP=1513652862/*!*/;

BEGIN/*!*/;

# at2888#171219 11:07:42 server id 1323307 end_log_pos 19727 CRC32 0x9edb1d95 Table_map: `replcrash`.`py_user` mapped to number 231# at2951#171219 11:07:42 server id 1323307 end_log_pos 19803 CRC32 0x18252616 Write_rows: table id 231flags: STMT_END_F

### INSERT INTO `replcrash`.`py_user`

### SET

### @1=2 /*INT meta=0 nullable=0 is_null=0*/### @2='9722XBCKISXDBSRDA5VA0A' /*VARSTRING(96) meta=96 nullable=1 is_null=0*/### @3='2017-12-19 11:07:42' /*DATETIME(0) meta=0 nullable=1 is_null=0*/### @4='1323307' /*VARSTRING(30) meta=30 nullable=1 is_null=0*/# at3027#171219 11:07:42 server id 1323307 end_log_pos 19834 CRC32 0x5e49e8d9 Xid = 295COMMIT/*!*/;

# Slave上的binlog信息

[root@ZST2 logs]# mysqlbinlog-v -vv --base64-output=decode-rows mysql-bin.000005...

# at19029#171219 11:07:42 server id 1323307 end_log_pos 19100 CRC32 0x70e91679 Query thread_id=26 exec_time=30 error_code=0SET TIMESTAMP=1513652862/*!*/;

BEGIN/*!*/;

# at19100#171219 11:07:42 server id 1323307 end_log_pos 19165 CRC32 0x9fcf7ba6 Table_map: `replcrash`.`py_user` mapped to number 231# at19165#171219 11:07:42 server id 1323307 end_log_pos 19246 CRC32 0x17e542da Write_rows: table id 231flags: STMT_END_F

### INSERT INTO `replcrash`.`py_user`

### SET

### @1=2 /*INT meta=0 nullable=0 is_null=0*/### @2='9722XBCKISXDBSRDA5VA0A' /*VARSTRING(96) meta=96 nullable=1 is_null=0*/### @3='2017-12-19 11:07:42' /*DATETIME(0) meta=0 nullable=1 is_null=0*/### @4='1323307' /*VARSTRING(30) meta=30 nullable=1 is_null=0*/### @5='2017-12-19 11:07:42' /*DATETIME(0) meta=0 nullable=1 is_null=0*/# at19246#171219 11:07:42 server id 1323307 end_log_pos 19277 CRC32 0x8557b6ea Xid = 249COMMIT/*!*/;

View Code

在relay-log/binlog中可以看到SET TIMESTAMP=1513652862/*!*/;

mydba@192.168.85.133,3307 [replcrash]> set timestamp=1513652862;select now();set timestamp=0;selectnow();

Query OK,0 rows affected (0.00sec)+---------------------+

| now() |

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

| 2017-12-19 11:07:42 |

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

1 row in set (0.00sec)

Query OK,0 rows affected (0.00sec)+---------------------+

| now() |

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

| 2017-12-20 10:48:49 |

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

1 row in set (0.00sec)

mydba@192.168.85.133,3307 [replcrash]>

View Code

正是由于設置了TIMESTAMP,從庫ins_time列使用current_timestamp默認值時就得到當時的時間。SBR的環境中,時間相關的函數(now(),current_date(),current_time()等),都能安全的復制到Slave的原因也是因為binlog中記錄有timestamp

因此上面添加列獲取Slave應用relay-log的時間肯定行不通。如果只是偶爾查看的話,可以從general-log中提取~.~

master_delay = N

An event received from the master is not executed until at least N seconds later than its execution on the master. The exceptions are that there is no delay for format description events or log file rotation events, which affect only the internal state of the SQL thread.

總結

以上是生活随笔為你收集整理的mysql relay log时间_如何得到Slave应用relay-log的时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。