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

Implementation example of video player based on Vue

When the existing video player cannot meet the ne...

Uniapp uses Baidu Voice to realize the function of converting recording to text

After three days of encountering various difficul...

Usage of if judgment in HTML

In the process of Django web development, when wr...

mysql 5.7.17 winx64.zip installation and configuration method graphic tutorial

Preface: I reinstalled win10 and organized the fi...

Detailed explanation of system input and output management in Linux

Management of input and output in the system 1. U...

How to filter out certain libraries during mysql full backup

Use the --all-database parameter when performing ...

Definition and function of zoom:1 attribute in CSS

Today I was asked what the zoom attribute in CSS ...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...

Embed codes for several older players

The players we see on the web pages are nothing m...

Detailed process of building mongodb and mysql with docker-compose

Let's take a look at the detailed method of b...

Native JavaScript to achieve the effect of carousel

This article shares the specific code for JavaScr...

Detailed analysis of the chmod command to modify file permissions under Linux

Use the Linux chmod command to control who can ac...