Monday, June 03, 2013

MySQL - Reading Bin Logs

BinLogs can be read in couple of ways. Here it is described in 3 ways: 

Using phpMyAdmin:

  •   Login to phpMyAdmin.
  •   Go to “Binary Log” tab
  •   Select Binary Logs to view
  •   Click GO
By default this would show 30 lines. So if you want to customize, click on EDIT and change the query according to your need.

Using SQL Query: 

  •    Determine existing binary logs on the system

mysql> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000022 | 104858289 |
| mysql-bin.000023 | 104857671 |
| mysql-bin.000024 | 104857898 |
| mysql-bin.000025 | 104857690 |
| mysql-bin.000026 | 104860121 |
| mysql-bin.000027 | 104858120 |
| mysql-bin.000028 | 104858421 |
| mysql-bin.000029 |  52091311 |
+------------------+-----------+

  •  From MySQL run the following for any existing binlog to read. I’ll try for 100 lines.
SHOW BINLOG EVENTS IN 'bin-log.000022' LIMIT 0, 100
-        
   Using UNIX Commands:
  •  From OS, we can directly read the binlogs. Here is how:
mysqlbinlog bin-log.000022
  • This can be modified and run with unix commands for customized reports.
mysqlbinlog bin-log.000022 |grep table_name |grep -v INSERT |cut -c1-1000



No comments: