MySQL BinLog Statement Retrieval

Posted by Jonathon on Stack Overflow See other posts from Stack Overflow or by Jonathon
Published on 2010-06-13T14:04:07Z Indexed on 2010/06/16 2:22 UTC
Read the original article Hit count: 332

Filed under:
|

I have seven 1G MySQL binlog files that I have to use to retrieve some "lost" information. I only need to get certain INSERT statements from the log (ex. where the statement starts with "INSERT INTO table SET field1="). If I just run a mysqlbinlog (even if per database and with using --short-form), I get a text file that is several hundred megabytes, which makes it almost impossible to then parse with any other program.

Is there a way to just retrieve certain sql statements from the log? I don't need any of the ancillary information (timestamps, autoincrement #s, etc.). I just need a list of sql statements that match a certain string. Ideally, I would like to have a text file that just lists those sql statements, such as:

INSERT INTO table SET field1='a';
INSERT INTO table SET field1='tommy';
INSERT INTO table SET field1='2';

I could get that by running mysqlbinlog to a text file and then parsing the results based upon a string, but the text file is way too big. It just times out any script I run and even makes it impossible to open in a text editor.

Thanks for your help in advance.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysqlbinlog