Detailed explanation of mysql's binlog

MySQL's binlog in detail

What is binlog The
binlog log is used to record all statements that have updated data or have potentially updated data (for example, a DELETE that does not match any row). Statements are saved as "events", which describe data changes.
The function of binlog
Because there is binlog for data update, it can be used for real-time backup, and
the parameters related to master/slave replication and binlog

log_bin
Setting this parameter means enabling the binlog function, and specifying the path name
log_bin_index
Setting this parameter is the path to specify the binary index file With the name
binlog_do_db,
this parameter indicates that only the binary log of the specified database is recorded.
binlog_ignore_db
This parameter indicates that the binary log of the specified database is not recorded.
max_binlog_cache_size
This parameter indicates the maximum size
of
the memory used by binlog. binlog_cache_use and binlog_cache_disk_use to help with testing.
       binlog_cache_use: number of transactions using the binary log cache
       binlog_cache_disk_use: number of transactions using the binary log cache but exceeding the binlog_cache_size value and using a temporary file to hold the statements in the transaction

max_binlog_size The
maximum value of Binlog, the maximum and default value is 1GB, this setting does not strictly control the size of Binlog, especially when Binlog is close to the maximum value and encounters a relatively large transaction, in order to ensure the integrity of the transaction, it is impossible to switch The action of the log can only record all the SQL of the transaction into the current log until the end of the transaction. The
sync_binlog
parameter directly affects the performance and integrity of mysql
sync_binlog=0:
When the transaction is committed, Mysql only writes the data in binlog_cache Enter the Binlog file, but do not execute disk synchronization instructions such as fsync to notify the file system to flush the cache to the disk, and let the Filesystem decide when to synchronize, which is the best performance.
sync_binlog=n, after n transaction submissions, Mysql will execute a disk synchronization command such as fsync, and the comrade file system will flush the Binlog file cache to the disk.
The default setting in Mysql is sync_binlog=0, that is, without any mandatory disk refresh instructions, the performance is the best at this time, but the risk is also the greatest. Once the system crashes, all Binlog information in the file system cache will be lost

. Binlog
deletion can be manually deleted or automatically deleted.
Automatically delete binlog
through the binlog parameter (expire_logs_days) to achieve mysql automatic deletion of binlog
mysql> show binary logs;
mysql > show variables like 'expire_logs_days';
mysql> set global expire_logs_days=3;
manually delete binlog
mysql> reset master; // delete master's binlog
mysql> reset slave; // delete slave's relay log
mysql> purge master logs before '2012-03-30 17:20 :00'; //Delete the binlog log file in the log index before the specified date
mysql> purge master logs to 'binlog.000002'; //Delete the binlog log file in the log index of the specified log file
or delete it directly with the operating system command

mysql> set sql_log_bin=1/0; //If the user has super permission, you can enable or disable the binlog record of the current session
mysql> show master logs; //View the master's binlog log
mysql> show binary logs; //View the master's Binlog log
mysql> show master status; //Used to provide status information of the master binary log file
mysql> show slave hosts; //Display the list of currently registered slaves. Slaves that do not start with the --report-host=slave_name option will not be displayed in the
binglog view in this list. You can view the contents of binlog
through mysqlbinlog command
[root@localhost ~]# mysqlbinlog  /home/mysql/binlog/binlog.000003  | more
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#120330 16:51:46 server id 1  end_log_pos 98    Start: binlog v 4, server v 5.0.45-log created 120330 1
6:51:46
# Warning: this binlog was not closed properly. Most probably mysqld crashed writing it.
# at 196
#120330 17:54:15 server id 1  end_log_pos 294   Query   thread_id=3     exec_time=2     error_code=0
SET TIMESTAMP=1333101255/*!*/;
insert into tt7 select * from tt7/*!*/;
# at 294
#120330 17:54:46 server id 1 end_log_pos 388 Query thread_id=3 exec_time=28 error_code=0
SET TIMESTAMP=1333101286/*!*/;
alter table tt7 engine=innodb/*!*/;

parsing binlog format
location
in file "at 196" indicates the starting point of the "event", which starts with the 196th byte; "end_log_pos 294" indicates that it ends with the 294th byte.

Timestamp Timestamp
of the event: "120330 17:54:46"

Event execution time
Event execution time: "exec_time=28"

Error code
Error code: "error_code=0" ID of the server

ID of the server: "server id 1"




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326136695&siteId=291194637