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.
- -d => which requires us to give a db name and to fetch the log file for a particular database
- –start-datetime => which is used to provide the start_date from which period the log should be fetched
- –stop-datetime => which is used to provide the stop date and to provide the range
- –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