Restore MySQL Database without overwriting tables from .sql file using sublime text

This is quick way to add _restore to your .sql backup file so you can restore old data and then change the name to table names you wish to restore.

I use sublime text and as most .sql backups will overwrite existing table you can use a regular expression to add _restore to each CREATE TABLE and INSERT INTO table name.

Use regex find and replace and use the following

  • Open your .sql file in Sublime Text
  • Click on Find > Replace
  • Make sure you bottom left searching by regular expression is depressed
  • Enter the find and replace fields the below information
  • Find: (?s)(CREATE TABLE|INSERT INTO) `(\w+)`
  • Replace: $1 `$2_restore`
  • Click replace all and your done.

That is all there is to it. You can now restore any table by renaming the original or even deleting it and renaming the _restore to the table name you just deleted.

Author: zastil

Web Developer and Director of Cheap Property Spain Ltd. Loves gaming, youtube creations and swimming and tenvis.

Leave a Reply

Your email address will not be published. Required fields are marked *