How to view mysql binlog (binary log)

How to view mysql binlog (binary log)

For example, when you create a new table or update data on an existing table, these events are stored in the mysql binlog, which is the binary log of the MySQL database.

Binary logs are very useful in MySQL replication, where the master server sends data from the binary log to the remote servers.

When you perform any type of recovery operation in MySQL, you are also dealing with binary log files.

The mysqlbinlog command is used to view the contents of the binary log in a readable, user-friendly format.

So how do we get and view mysql binlog (binary log)?

The following is a command method to obtain the current binary log list.

Execute the following show binary logs command from mysql which will display all binary logs in the system.

mysql> SHOW BINARY LOGS;
+-------------------+----------+
| Log_name | File_size |
+-------------------+----------+
|mysqld-bin.000001 | 15740 |
|mysqld-bin.000002 | 3319 |
..
..

If binary logging is not enabled on your system, you will see the following error message.

mysql> SHOW BINARY LOGS;
ERROR 1381 (HY000): You are not using binary logging

Where is the mysql binlog location?

By default, the binary log files are located in the /var/lib/mysql directory as shown below.

# ls -l /var/lib/mysql/
-rw-rw----. 1 mysql mysql 15740 Aug 16 14:57 mysqld-bin.000001
-rw-rw----. 1 mysql mysql 3319 Aug 16 14:57 mysqld-bin.000002
..
..

You may also be interested in:
  • Detailed explanation of MySQL database binlog cleanup command
  • 3 common errors in reading MySQL Binlog logs
  • 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)
  • How to automatically clean up MySQL binlog logs
  • Teach you to automatically restore the log file (binlog) of the MySQL database
  • [MySQL binlog] How to thoroughly parse binlog in Mixed log format in MySQL
  • Detailed explanation of mysql binlog binary log
  • Parsing MySQL binlog

<<:  Build a server virtual machine in VMware Workstation Pro (graphic tutorial)

>>:  Three ways to implement virtual hosts under Linux7

Recommend

What does this.parentNode.parentNode (parent node of parent node) mean?

The parent node of the parent node, for example, t...

How to implement MySQL master-slave replication based on Docker

Preface MySQL master-slave replication is the bas...

Detailed example of removing duplicate data in MySQL

Detailed example of removing duplicate data in My...

MySQL free installation version configuration tutorial

This article shares the MySQL free installation c...

Bundling non-JavaScript static resources details

Table of contents 1. Custom import in packaging t...

Graphical tutorial on installing CentOS 7.3 on VMWare

Illustrated CentOS 7.3 installation steps for you...

A brief analysis of the difference between FIND_IN_SET() and IN in MySQL

I used the Mysql FIND_IN_SET function in a projec...

How to Fix File System Errors in Linux Using ‘fsck’

Preface The file system is responsible for organi...

SQL implementation of LeetCode (183. Customers who have never placed an order)

[LeetCode] 183.Customers Who Never Order Suppose ...

Solve the conflict between docker and vmware

1. Docker startup problem: Problem Solved: You ne...

Detailed explanation of Nginx timeout configuration

I recently used nginx in a project, and used Java...