Home >Database >Mysql Tutorial >How to read mysql binlog

How to read mysql binlog

藏色散人
藏色散人Original
2019-01-30 16:23:376459browse

In MySQL or MariaDB, whenever you make a change to the database, that specific event is logged.

How to read mysql binlog

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

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

When you perform any type of recovery operation in MySQL, you will also process binary log files.

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

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

The following is an introduction to the 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 your system does not have binary logging enabled, you will see the following error message.

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

Where is the location of mysql binlog?

By default, the binary log file is 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
..
..

Recommended reference for free learning: "mysql tutorial"

The above is the detailed content of How to read mysql binlog. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn