mysql打开和查看binlog

打开binlog
修改my.cnf,添加log-bin配置项

log-bin=binlog

使用mysql客户端查看binlog
(1)查看所有日志文件:

show binary logs;

mysql> show binary logs;

+—————+———–+

| Log_name | File_size |

+—————+———–+

| binlog.000001 | 870 |

+—————+———–+

1 row in set (0.00 sec)

(2)查看正在写入的日志文件:

show master status;

mysql> show master status;

+—————+———-+————–+——————+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+—————+———-+————–+——————+

| binlog.000001 | 870 | | |

+—————+———-+————–+——————+

1 row in set (0.00 sec)

(3)查看当前binlog文件内容:

show binlog events;

mysql> show binlog events;

+—————+—–+————-+———–+————-+—————————————————+

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

+—————+—–+————-+———–+————-+—————————————————+

| binlog.000001 | 4 | Format_desc | 1 | 107 | Server ver: 5.5.34-log, Binlog ver: 4 |

| binlog.000001 | 107 | Query | 1 | 173 | BEGIN |

| binlog.000001 | 173 | Query | 1 | 269 | use `im`; insert into user values(3,”yangyg”) |

| binlog.000001 | 269 | Xid | 1 | 296 | COMMIT /* xid=4 */ |

| binlog.000001 | 296 | Query | 1 | 362 | BEGIN |

| binlog.000001 | 362 | Query | 1 | 460 | use `im`; insert into user values(4,”lidong01″) |

| binlog.000001 | 460 | Xid | 1 | 487 | COMMIT /* xid=5 */ |

| binlog.000001 | 487 | Query | 1 | 553 | BEGIN |

| binlog.000001 | 553 | Query | 1 | 650 | use `im`; insert into user values(5,”sunxuan”) |

| binlog.000001 | 650 | Xid | 1 | 677 | COMMIT /* xid=6 */ |

| binlog.000001 | 677 | Query | 1 | 743 | BEGIN |

| binlog.000001 | 743 | Query | 1 | 843 | use `im`; insert into user values(6,”chendong01″) |

| binlog.000001 | 843 | Xid | 1 | 870 | COMMIT /* xid=34 */ |

+—————+—–+————-+———–+————-+—————————————————+

13 rows in set (0.00 sec)

评论关闭。