Home > Databases > How to Read MySQL Binary Logs

How to Read MySQL Binary Logs

mysqllogoMySQL database server utilizes a transaction log to track all of the modifications performed within the databases. This log ensures both that the database is able to recover when abruptly interrupted (such as a loss of power) and that users are able to undo (or “rollback” in database language) the results of a database transaction. Except for the cases where the administrator has disabled or commented out the log-bin parameter in my.cfg file, this log is generated by default. As the name implies, binary log (transaction log) files are written in binary format, but sometimes you may need to examine the content of the transaction logs in text format, where the mysqlbinlog utility will come in handy.

A binlog file normally is named hostname-bin.xxxxx and stored in /var/lib/mysql directory. It cannot be opened and read straight away as it’s a binary file so we can make use of mysqlbinlog command.

For example, to display the contents of the binary log file named localhost-bin.000004, use this command:

mysqlbinlog localhost-bin.000004

The output includes all events contained in localhost-bin.000004. Event information includes the statement executed, the time the statement took, the thread ID of the client that issued it, the timestamp when it was executed, and so forth.

The binlogs are likely to be very huge thus making it almost impossible to read anything on screen. However, you can pipe the output into a file which can be open up for later browsing in text editor:

mysqlbinlog localhost-bin.000004 > filename.txt

To reduce the amount of data retrieved from binary logs, there are several options that can be used to limit the data that is been returned. Among the useful ones are listed below:



The datetime value is relative to the local time zone on the machine where you run mysqlbinlog. The value should be in a format accepted for the DATETIME or TIMESTAMP data types. For example:

mysqlbinlog --start-datetime="2008-05-22 00:00:00" --stop-datetime="2008-05-29 00:00:00" localhost-bin.000004

For more information, you can take a look at the official mysqlbinlog documentation.

Categories: Databases Tags: ,
  1. gurl
    February 23, 2009 at 07:20

    im new in linux +phpmyadmin
    i have already installed phpmyadmin in my pc fedora 7
    can anyone help me
    what is the command for me to write in the command line to start using phpmyadmin in gui?
    one more thing,how can i import file .pcap into mysql?
    can it be readable later on?

  2. pcabrerat
    October 7, 2009 at 14:17

    phpmyadmin uses a web interface. You have to open a web brower and point it to the path where you installed phpmyadmin. It might be something like “”

  3. andrew
    March 26, 2010 at 10:35

    Can we transport localhost-bin.00000 to another PC and run the reading from there?

  4. neomancer
    March 26, 2010 at 13:21

    @andrew as long as you have the mysqlbinlog utility, yes.

  5. July 20, 2014 at 03:01

    Users can choose their systems depending upon the size of the property
    and requirements desired to them. Besides getting information on the positive and
    negative aspect of any device, reviews also offer information on the feature of the
    gadget. They could similarly be utilized to stop vehicle drivers from
    using your gateway or driveway as a way to turn their
    autos around.

  6. February 23, 2016 at 06:29

    Great post.

  7. June 2, 2017 at 00:00

    Your personal view on binary options trading is nicely planned out, I most certainly will share
    this with my readership.

  8. June 8, 2017 at 00:03

    I trust that it’s all right that I share this with a couple
    of my visitors, this will assist their familiarity with binary options trading greatly.

  9. June 15, 2017 at 00:10

    I expect that it’s alright that I write about this with many
    of my customers, it will help their familiarity with
    binary options trading considerably.

  10. July 5, 2017 at 00:33

    This is really among the finest options blog sites I’ve examined
    in years.

  11. July 6, 2017 at 00:30

    We should feature a talk some time on the subject of options and what we could do to ensure that it is
    greater for everyone.

  12. July 7, 2017 at 00:08

    Let’s have a discussion some time concerning
    options and just what we can do to make it improved for any one.

  13. July 8, 2017 at 00:00

    I’ve truly never implemented this approach, appreciate your posting it.

  14. Joanna Pfeil
    March 31, 2018 at 16:52

    This site is just awesome. I’ve looked these informations a long time and I
    view it that is good written, easy to comprehend.

    I congratulate you for this article that I’ll recommend to prospects around.
    I ask you to visit the gpa-calculator.co site where each scholar or scholar can calculate results grade point average rating.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: