Wednesday 18 July 2018

MYSQL Binary Logs And Purge

MYSQL Binary Logs And Purge

In one of our projects we were required to keep track of the changes in the database for a particular period of time. MySQL has an inbuilt functionality for saving information on data modification for a specific period of time in log files.
 
To display content of a binary log , myslbinlog command can be called. However, this command also requires parameters including the log file name. A proper invocation of this method would look like the following.
mysqlbinlog [options] log_file..
There are plenty of options available but for demonstration’s sake I will describe a few only.
 
  1. -d => which requires us to give a db name and to fetch the log file for a particular database
  2. –start-datetime => which is used to provide the start_date from which period the log should be fetched
  3. –stop-datetime => which is used to provide the stop date and to provide the range
  4. –read-from-remote-server => it is used to fetch the binary log from remote server provided we give the right host name and password
Besides these, there are many more options available which can be found in MySQL documentation.
 
To get a binary log file we can use something like –
shell> mysqlbinlog bin.001 > test.txt // which is used to put the log in text format
PURGING IN BINARY LOGS
Purge is used to delete the binary logs from the bin. It can used by the following syntax.
PURGE { BINARY | MASTER } LOGS
{ TO ‘log_name‘ | BEFOREdatetime_expr}

Additional Information
  1. There are other logs such as query log which tracks of all the query takes palce
  2. Binary logs are somewaht different from query logs
  3. we can use SHOW BINARY LOGS to show the logs.

0 comments:

Post a Comment