未加星标

MySQL查看binlog日志内容

字体大小 | |
[数据库(mysql) 所属分类 数据库(mysql) | 发布者 店小二05 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

mysql的binlog日志位置可通过show variables like '%datadir%';查看,直接打开无法查看,要看其内容2个办法:

1、登录到mysql查看binlog

只查看第一个binlog文件的内容

mysql> show binlog events;

查看指定binlog文件的内容

mysql> show binlog events in 'mysql-bin.000002';

mysql> show binlog events in 'mysql-bin.000001';

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

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

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

| mysql-bin.000001 | 4 | Format_desc | 195 | 106 | Server ver: 5.1.73-log, Binlog ver: 4 |

| mysql-bin.000001 | 106 | Query | 195 | 198 | use `Hadoop`; delete from user where id=3 |

| mysql-bin.000001 | 198 | Intvar | 195 | 226 | INSERT_ID=4 |

| mysql-bin.000001 | 226 | Query | 195 | 332 | use `hadoop`; INSERT INTO user (id,name)VALUES (NULL,1) |

| mysql-bin.000001 | 332 | Query | 195 | 424 | use `hadoop`; delete from user where id=3 |

| mysql-bin.000001 | 424 | Intvar | 195 | 452 | INSERT_ID=5 |

| mysql-bin.000001 | 452 | Query | 195 | 560 | use `hadoop`; INSERT INTO user (id,name)VALUES (NULL,222) |

| mysql-bin.000001 | 560 | Query | 195 | 660 | use `hadoop`; DELETE FROM `user` WHERE (`id`='1') |

| mysql-bin.000001 | 660 | Intvar | 195 | 688 | INSERT_ID=6 |

| mysql-bin.000001 | 688 | Query | 195 | 795 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('555') |

| mysql-bin.000001 | 795 | Intvar | 195 | 823 | INSERT_ID=7 |

| mysql-bin.000001 | 823 | Query | 195 | 930 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('555') |

| mysql-bin.000001 | 930 | Intvar | 195 | 958 | INSERT_ID=8 |

| mysql-bin.000001 | 958 | Query | 195 | 1065 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('555') |

| mysql-bin.000001 | 1065 | Intvar | 195 | 1093 | INSERT_ID=9 |

| mysql-bin.000001 | 1093 | Query | 195 | 1200 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('555') |

| mysql-bin.000001 | 1200 | Query | 195 | 1300 | use `hadoop`; DELETE FROM `user` WHERE (`id`='9') |

| mysql-bin.000001 | 1300 | Query | 195 | 1400 | use `hadoop`; DELETE FROM `user` WHERE (`id`='8') |

| mysql-bin.000001 | 1400 | Query | 195 | 1500 | use `hadoop`; DELETE FROM `user` WHERE (`id`='7') |

| mysql-bin.000001 | 1500 | Query | 195 | 1600 | use `hadoop`; DELETE FROM `user` WHERE (`id`='4') |

| mysql-bin.000001 | 1600 | Query | 195 | 1700 | use `hadoop`; DELETE FROM `user` WHERE (`id`='5') |

| mysql-bin.000001 | 1700 | Query | 195 | 1800 | use `hadoop`; DELETE FROM `user` WHERE (`id`='6') |

| mysql-bin.000001 | 1800 | Intvar | 195 | 1828 | INSERT_ID=10 |

| mysql-bin.000001 | 1828 | Query | 195 | 1935 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('555') |

| mysql-bin.000001 | 1935 | Intvar | 195 | 1963 | INSERT_ID=11 |

| mysql-bin.000001 | 1963 | Query | 195 | 2070 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('666') |

| mysql-bin.000001 | 2070 | Intvar | 195 | 2098 | INSERT_ID=12 |

| mysql-bin.000001 | 2098 | Query | 195 | 2205 | use `hadoop`; INSERT INTO `user` (`name`) VALUES ('777') |

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

查看当前正在写入的binlog文件

mysql> show master status\G

mysql> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000002

Position: 106

Binlog_Do_DB:

Binlog_Ignore_DB: mysql,information_schema,performance_schema

1 row in set (0.00 sec)

获取binlog文件列表

mysql> show binary logs;

mysql> show binary logs;

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

| Log_name | File_size |

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

| mysql-bin.000001 | 3548 |

| mysql-bin.000002 | 106 |

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

2 rows in set (0.00 sec)

2、用mysqlbinlog工具查看

基于开始/结束时间

[root@hd3 ~]# mysqlbinlog --start-datetime='2016-08-02 00:00:00' --stop-datetime='2016-08-03 23:01:01' -d hadoop /var/lib/mysql/mysql-bin.000001

基于pos值,注:hadoop是库名,/var/lib/mysql/mysql-bin.000001是二进制文件路径

[root@hd3 ~]# mysqlbinlog --start-position=2098 --stop-position=2205 -d hadoop /var/lib/mysql/mysql-bin.000001

/*!40019 SET @@session.max_insert_delayed_threads=0*/;

/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

DELIMITER /*!*/;

# at 4

#160803 17:49:51 server id 195 end_log_pos 106 Start: binlog v 4, server v 5.1.73-log created 160803 17:49:51 at startup

# Warning: this binlog is either in use or was not closed properly.

ROLLBACK/*!*/;

BINLOG '

P76hVw/DAAAAZgAAAGoAAAABAAQANS4xLjczLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAA/vqFXEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC

'/*!*/;

# at 2098

#160803 18:53:56 server id 195 end_log_pos 2205 Query thread_id=1481 exec_time=115 error_code=0

use `hadoop`/*!*/;

SET TIMESTAMP=1470221636/*!*/;

SET @@session.pseudo_thread_id=1481/*!*/;

SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;

SET @@session.sql_mode=0/*!*/;

SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;

/*!\C utf8 *//*!*/;

SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;

SET @@session.lc_time_names=0/*!*/;

SET @@session.collation_database=DEFAULT/*!*/;

INSERT INTO `user` (`name`) VALUES ('777')

/*!*/;

DELIMITER ;

# End of log file

ROLLBACK /* added by mysqlbinlog */;

/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

linux公社的RSS地址 : https://www.codesec.net/rssFeed.aspx

本文地址: https://www.codesec.net/Linux/2019-01/156136.htm

本文数据库(mysql)相关术语:navicat for mysql mysql workbench mysql数据库 mysql 存储过程 mysql安装图解 mysql教程 mysql 管理工具

代码区博客精选文章
分页:12
转载请注明
本文标题:MySQL查看binlog日志内容
本站链接:https://www.codesec.net/view/628570.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mysql) | 评论(0) | 阅读(224)