Post

Mysql binlog

Configurations

Mysql binary log is rotated. The threshold is controlled by max_binlog_size option. AWS RDS uses a stored procedure to control the retention period of binary logs CALL mysql.rds_show_configuration;.

Binlog can have a few different format: STATEMENT, ROW or MIXED.

1
2
3
4
5
6
mysql> show variables like 'binlog_format';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+

How to view binary logs

There are two ways to view the binary logs. But first we need to list all available binary logs.

1
2
3
4
5
6
7
8
9
mysql> show binary logs;
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000001 |  87502922 | No        |
| binlog.000002 |       180 | No        |
| binlog.000003 |  13855131 | No        |
| binlog.000004 |  43809965 | No        |
+---------------+-----------+-----------+

View binary logs inside mysql shell

SHOW BINLOG EVENTS

Use mysqlbinlog command

Note the --stop-never parameter can keep the connection open and stream new log after log rotation.

Programmatically subscribe to bin logs

Binlog network stream allows application to programmatically subscribe bin logs. After your application registers itself to the master db, it can receive bin logs. mysql-binlog-connector-java has an example implementation of using binlog network stream to obtain a continuous stream of bin logs.

This post is licensed under CC BY 4.0 by the author.