How to open MySQL binlog log

How to open MySQL binlog log

binlog is a binary log file, which records all mysql dml operations. Through binlog logs, we can perform data recovery, master-slave replication, and so on. Developers may not pay much attention to binlog, but it is very important for operation and maintenance or architecture personnel.

How to enable mysql binlog?

Add three lines directly to the my.inf main configuration file

log_bin=ON
log_bin_basename=/var/lib/mysql/mysql-bin
log_bin_index=/var/lib/mysql/mysql-bin.index

Three parameters to specify,
The first parameter is to open the binlog log. The second parameter is the base file name of the binlog log. The third parameter specifies the index file of the binlog file, which manages the directory of all binlog files.

Of course, there is also a simple configuration, which can be done with one parameter

log-bin=/var/lib/mysql/mysql-bin

The function of this parameter is the same as the above three. MySQL will automatically set log_bin to on state according to this configuration, and automatically set the log_bin_index file to the file name you specify followed by .index

After these configurations are completed, it should be possible for versions below 5.7, but if we are using version 5.7 or above at this time, restarting the MySQL service will result in an error. At this time we must also specify a parameter

server-id=123454

Randomly assign a string that cannot be the same as the name of other machines in the cluster. If there is only one machine, you can assign it at random.

With the above configuration, we can restart our mysql

CentOS 6
service mysqld restart
 
 
CentOS 7
systemctl restart mysqld

After successful startup, we can log in to see if our configuration works

show variables like '%log_bin%' 

Let's find this directory and take a look.

Because I have already operated the database here, I can see that there are multiple mysql-bin files and a mysql-bin.index file. We can open this file to take a look.

At this point, our binlog log is opened.

For specific operations on binlog logs, please refer to
Detailed explanation of binlog log: https://www.jb51.net/article/207954.htm
Use binlog to restore data: https://www.jb51.net/article/207957.htm

This is the end of this article about the steps to enable MySQL binlog. For more information about enabling MySQL binlog, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL uses binlog logs to implement data recovery
  • Detailed explanation of MySQL binlog usage
  • Detailed explanation of the binlog log analysis tool for monitoring MySQL: Canal
  • Detailed explanation of MySQL database binlog cleanup command
  • 3 common errors in reading MySQL Binlog logs
  • How to view mysql binlog (binary log)
  • Two ways to correctly clean up mysql binlog logs
  • Explain MySQL's binlog log and how to use binlog log to recover data
  • Summary of Binlog usage of MySQL database (must read)
  • Comparative Analysis of MySQL Binlog Log Processing Tools

<<:  Solve the conflict between docker and vmware

>>:  Web Design: The Accurate Location and Use of Massive Materials

Recommend

Suggestions on creating business HTML emails

Through permission-based email marketing, not onl...

Summary of two methods to implement vue printing function

Method 1: Install the plugin via npm 1. Install n...

vue cli3 implements the steps of packaging by environment

The vue project built with cli3 is known as a zer...

The vue project realizes drawing a watermark in a certain area

This article shares with you how to use Vue to dr...

Talk about how to identify HTML escape characters through code

Occasionally you'll see characters such as &#...

Detailed explanation of this pointing in JS arrow function

Arrow function is a new feature in ES6. It does n...

Detailed explanation of the difference between CSS link and @import

How to add css in html? There are three ways to s...

Web page text design should be like smart girls wearing clothes

<br />"There are no ugly women in the w...

Graphic tutorial for installing MySQL 5.6.35 on Windows 10 64-bit

1. Download MySQL Community Server 5.6.35 Downloa...

HTML left, center, right adaptive layout (using calc css expression)

In the latest HTML standard, there is a calc CSS e...

Example code for implementing equal height layout in multiple ways with CSS

The equal height layout described in this article...

Pitfall notes of vuex and pinia in vue3

Table of contents introduce Installation and Usag...

Detailed discussion of InnoDB locks (record, gap, Next-Key lock)

Record lock locks a single index record. Record l...

A Brief Analysis of MySQL - MVCC

Version Chain In InnoDB engine tables, there are ...