MySQL 5.7.25 binary log configuration and introduction

Keywords: Database MySQL Ubuntu SQL

The binlog log function of MySQL is used to record the updated contents (changes to the database) of MySQL database, such as the internal addition, deletion, modification and query of MySQL. The query select or show of the database will not be recorded by the binlog log log. It is mainly used for the master-slave copy and increment recovery of the database. This article explains binlog based on MySQL 5.7.25 installed in Ubuntu 16.04.

Configure binlog

After mysql 5.7, there is no template for my.cnf. Please search for binlog configuration.

The main parameters of binlog configuration are as follows:

[mysqld]

server-id = 1

log\_bin = mysql-bin

Check whether binlog is enabled

After logging in mysql, use the following command:

show variables like '%log\_bin%';

The results are as follows:

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

| Variable\_name                   | Value                          |

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

| log\_bin                         | ON                             |

| log\_bin\_basename                | /var/lib/mysql/mysql-bin       |

| log\_bin\_index                   | /var/lib/mysql/mysql-bin.index |

| log\_bin\_trust\_function\_creators | OFF                            |

| log\_bin\_use\_v1\_row\_events       | OFF                            |

| sql\_log\_bin                     | ON                             |

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

6 rows in set (0.00 sec)

View binlog name

The command to view the binlog name is as follows:

show binary logs;

The results are as follows:

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

| Log\_name         | File\_size |

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

| mysql-bin.000001 |       177 |

| mysql-bin.000002 |       462 |

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

2 rows in set (0.00 sec)

View binlog details

The commands for viewing the binlog are as follows:

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

The results are as follows:

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

| Log\_name         | Pos | Event\_type     | Server\_id | End\_log\_pos | Info                                  |

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

| mysql-bin.000001 |   4 | Format\_desc    |         1 |         123 | Server ver: 5.7.25-log, Binlog ver: 4 |

| mysql-bin.000001 | 123 | Previous\_gtids |         1 |         154 |                                       |

| mysql-bin.000001 | 154 | Stop           |         1 |         177 |                                       |

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

3 rows in set (0.00 sec)

Posted by delxy on Sun, 01 Dec 2019 22:51:48 -0800