当前位置:网站首页>Mysql, binlog log query
Mysql, binlog log query
2022-04-23 04:32:00 【The hunter is eating meat】
List of articles
One 、 Turn on binlog
stay mysql The configuration file my.cnf in , Turn on log-bin function ,log-bin=mysql-bin
Make sure it's on .
[mysqld]
log-bin=mysql-bin
explain , value mysql-bin Is the base name or prefix name of the log .
Two 、 adopt mysql Variable configuration table of , Check whether the binary log is turned on
mysql> show variables like 'log%';
+----------------------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------------------+--------------------------------------+
| log_bin | ON | ---> ON, Indicates that it has been turned on binlog journal
| log_bin_basename |/usr/local/mysql/data/mysql-bin | ---> binlog Log storage location
| log_bin_index |/usr/local/mysql/data/mysql-bin.index | ---> binlog Format of log
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| log_builtin_as_identified_by_password | OFF |
| log_error | /data1/mysql/logs/error.log |
| log_error_verbosity | 3 |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | ON |
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| log_statements_unsafe_for_binlog | ON |
| log_syslog | OFF |
| log_syslog_facility | daemon |
| log_syslog_include_pid | ON |
| log_syslog_tag | |
| log_throttle_queries_not_using_indexes | 0 |
| log_timestamps | UTC |
| log_warnings | 2 |
+----------------------------------------+--------------------------------------+
3、 ... and 、binlog Log content viewing
1、mysql see binlog command
mysql> show binlog events; # Just look at the first binlog The content of the document
mysql> show binlog events in 'mysql-bin.000002'; # View specified binlog The content of the document
mysql> show binary logs; # obtain binlog File list
mysql> show master status; # View what is currently being written binlog file
2、 find mysqlbinlog command
mysqlbinlog It's a check mysql Binary log tool , You can put mysql All the above operation records are exported from the log , The default installation path of this tool is :/usr/local/mysql/bin/mysqlbinlog
.
You can find... Through the command mysqlbinlog Tool path for :
find / -name "mysqlbinlog"
3、 Use mysqlbinlog command
bin log
It's binary , Binary files save more space , Write faster , You can't open it directly to view .
(1) If log-bin The file is relatively small , You can view the log directly :
/usr/local/mysql/bin/mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.0007
--no-defaults
It can be omitted , Reference resources Below mysqlbinlog abnormal
explain .
(2) take log-bin The parsed log is transferred to the specified file
/usr/local/mysql/bin/mysqlbinlog --no-defaults/usr/local/mysql/data/mysql-bin.0007 > /tmp/mysql_bin_07.sql
(3) Based on start and end times :
/usr/local/mysql/bin/mysqlbinlog --start-datetime="2021-10-01 00:00:00" --stop-datetime="2021-10-21 23:59:59" /usr/local/mysql/data/mysql-bin.0007 -r test2.sql
(4) Add filtration , Query only insert、update、delete The sentence of , Use more Check it out. :
/usr/local/mysql/bin/mysqlbinlog --no-defaults --database=raceEnroll mysql-bin.000007 |grep update | more
4、mysqlbinlog abnormal
direct perform /usr/local/mysql/bin/mysqlbinlog mysql-bin.000007
When the log , The following errors may be reported :
mysql> /usr/local/mysql/bin/mysqlbinlog mysql-bin.000007
mysqlbinlog: [ERROR] unknown variable 'default-character-set=utf8mb4'
mysqlbinlog: [ERROR] unknown variable 'default-character-set=utf8'
reason :
mysqlbinlog This tool doesn't recognize binlog In the configuration of default-character-set=utf8mb4
This instruction .
resolvent :
add to --no-defaults
Parameters , namely : /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000007
.
Four 、 frequently-used Binlog Operation command
# Is it enabled? binlog journal
show variables like 'log_bin';
# View detailed log configuration information
show global variables like '%log%';
# mysql Data storage directory
show variables like '%dir%';
# see binlog The catalog of
show global variables like "%log_bin%";
# View the... Currently used by the server biglog File and size
show binary logs;
# Check the... Used by the main server biglog File and size
# Check out the latest binlog Log file name and Position
show master status;
# Event query command
# IN 'log_name' : Specify the binlog file name ( No designation is the first binlog file )
# FROM pos : Specify from which pos Start from ( Do not specify is from the entire file first pos Start at )
# LIMIT [offset,] : Offset ( No designation is 0)
# row_count : Total number of queries ( Not specifying is all lines )
show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
# see binlog Content
show binlog events;
# Check out a specific binlog The content of the document (in The back is binlog The name of the file )
show binlog events in 'master.000003';
# Set up binlog File save event , Expired delete , Unit day
set global expire_log_days=3;
# Delete the current binlog file
reset master;
# Delete slave The trunk log of
reset slave;
# Delete the log index before the specified date binlog Log files
purge master logs before '2019-03-09 14:00:00';
# Delete the specified log file
purge master logs to 'master.000003';
版权声明
本文为[The hunter is eating meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230417435912.html
边栏推荐
- 【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
- 顺序表的基本操作
- As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
- Basic use of shell WC (counting the number of characters)
- 【论文阅读】【3d目标检测】point transformer
- 国外LEAD,联盟经理常见问答
- win10, mysql-8.0.26-winx64.zip 安装
- Set经典小题目
- matlab讀取多張fig圖然後合並為一張圖(子圖的形式)
- Go反射—Go语言圣经学习笔记
猜你喜欢
Go反射法则
Phishing for NFT
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
VSCode配置之Matlab极简配置
Supplement: Annotation
Nature medicine reveals individual risk factors of coronary artery disease
Alibaba cloud IOT transfer to PostgreSQL database scheme
兼容NSR20F30NXT5G的小体积肖特基二极管
STM32F4单片机ADC采样及ARM-DSP库的FFT
小红书被曝整体裁员20%,大厂之间内卷也很严重
随机推荐
mysql ,binlog 日志查询
mysql table 中增加列的SQL语句
C语言: 指针的进阶
What is software acceptance testing? What are the benefits of acceptance testing conducted by third-party software testing institutions?
Chapter 4 - understanding standard equipment documents, filters and pipelines
[BIM introduction practice] Revit building wall: detailed picture and text explanation of structure, envelope and lamination
補:注解(Annotation)
Common string processing functions in C language
A lifetime of needs, team collaboration can play this way on cloud nailing applet
[AI vision · quick review of NLP natural language processing papers today, No. 32] wed, 20 APR 2022
Bacterial infection and antibiotic use
无线充电全国产化电子元件推荐方案
Understand the gut organ axis, good gut and good health
针对NFT的网络钓鱼
Network principle | connection management mechanism in TCP / IP important protocol and core mechanism
The perfect combination of collaborative process and multi process
[echart] démarrer avec echart
MySQL 2013 lost connection to MySQL server during query
2019 is coming to an end, the longest day.
无线键盘全国产化电子元件推荐方案