In MySQL or MariaDB, whenever you make a change to the database, that specific event is logged.
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!