Search code examples
phpmysqlregexbashbinary-log

How To Remove Specific Query From MySQL Binary Log


So I have a binary log that's taking forever to restore to because of some poorly written code that updates a table every second or so for every user that's currently logged in. Of course the restore process is restoring every one of these lines and making the script take way longer than it needs to.

What would be the quickest way to update this file to remove that specific query from all of my binary logs? I have this PHP script that I tested and it worked on a smaller file, but preg_replace seemed to have some limits (or maybe just PHP as a whole) when it came to the file size.

Here's my PHP line:

file_put_contents("/logs/restore.sql",preg_replace("/use(?:.|\n)+?update `notifi(?:.|\n)+?COMMIT\/\*\!\*\/;/mui",'',file_get_contents("/logs/restorex.sql")));

The Regex in there seemed to be working great with the smaller file, it's just that I'm not as good with any other languages (PHP is my main language) to know what I should be using, or how to implement that Regex into something else.


Solution

  • If you are willing to throw away all data in that table,

     ALTER TABLE notifications ENGINE=BLACKHOLE;
    

    Then the queries would zip by because they would do nothing.