当前位置:网站首页>MySQL data loss, analyze binlog log file

MySQL data loss, analyze binlog log file

2022-07-07 04:02:00 Little snail's way

scene : A part of the business data that should exist is found missing in the test environment

a Table related b Table business data includes 28 The data of , however a The watch doesn't , late mysql Log view reason !

Belonging to account general_log The directory where the files are stored


mysql> SHOW VARIABLES LIKE 'gen%';
+----------------------------------+----------------------------+
| Variable_name                    | Value                      |
+----------------------------------+----------------------------+
| general_log                      | OFF                        |
| general_log_file                 | /var/lib/mysql/server6.log |
| generated_random_password_length | 20                         |
+----------------------------------+----------------------------+
3 rows in set (0.01 sec)

Then you can go to the corresponding general_log Go to the directory to see the execution log .

see binlog

 Command line login database :mysql -uroot -p123456
show binary logs;

mysql> show binary logs
    -> ;
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000001 | 385141819 | No        |
+---------------+-----------+-----------+

If you need to query 2022-06-28 00:00:00 To 2022-06-28 23:59:50 The database for test Operation log of , Enter the following command to write the data to a standby txt that will do

   mysqlbinlog --no-defaults --database=test --base64-output=decode-rows -v --start-datetime="2022-06-28 00:00:00" --stop-datetime="2022-06-28 23:59:50" binlog.000001 > test.txt;

--base64-output=decode-rows -v Parameters :

  • base64-output, You can control the output of the output statement base64 Coded BINLOG sentence ;
  • decode-rows: Option will decode the row based event into a SQL sentence

adopt vi command ,/ keyword Query correlation sql

Pictured :
 Insert picture description here
Check the log , It turns out that the table is in 29 Japan 9:55:41 Seconds were deleted and recreated , All business data is lost !!!

Binlog Analytical skills

  • Try to parse from the library , Avoid affecting the main library
  • First, roughly locate the related library table operations binlog, Then analyze the corresponding binlog Data in
  • In parsing DDL There is no need to add -v Output details ( Speed up parsing )
  • If it's on binlog_rows_query_log_events Parameters , Need to use -vv Parameters can display specific SQL sentence
原网站

版权声明
本文为[Little snail's way]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207062110253942.html