Database Search and Replace Script in PHP

Search Replace DB version 3.0.0 (currently a BETA version) allows you to carry out database wide search/replace actions that don’t damage PHP serialized strings or objects with a user friendly interface and experience.

Installation & Use

search-replace-mobile-screenshot Now acts like a web app!

To use the script, download the zip file from below, extract the folder called secret-name-please, renaming it to something secret of your choosing, then navigate to that folder in your browser. The script will automatically attempt to find and populate the database field but you must check that the details are correct and that it is for the database you wish to carry out a search/replace operation on.

To see how you can use this tool to aid migrations, check out our article on WordPress migrations or visit the WP Tuts+ article that mentions this script.

If you are in any doubt whatsoever about how to use this standalone script, then please consider getting an expert in.  It’s a really powerful bit of code that if used badly can damage a WP install beyond repair.  If you want help, get in somebody like us, for example, or any of the other great guys listed over at CodePoet.

IMPORTANT: This code is supplied with no warranty or support implied. You use it entirely at your own risk. The code is licensed under the GPL V3 and you should be aware of its limitations and how they affect you and your use of this code. Please also read the instructions and warnings provided and always take a verified backup of your database before starting.

Download v 3.0.0 BETA

Problems? Try v 2.1.0 STABLE


* Version 3.0.0:
* Major overhaul
* * Multibyte string replacements
* * UI completely redesigned
* * Removed all links from script until ‘delete’ has been clicked to avoid
* security risk from our access logs
* * Search replace functionality moved to it’s own separate class
* * Replacements done table by table to avoid timeouts
* * Convert tables to InnoDB
* * Convert tables to utf8_unicode_ci
* * Use PDO if available
* * Preview/view changes
* * Optionally use preg_replace()
* * Scripts bootstraps WordPress/Drupal to avoid issues with unknown
* serialised objects/classes
* * Added marketing stuff to deleted screen (sorry but we’re running a
* business!)
* Version 2.2.0 (never formally released but patched into v3.0.0):
* * Added remove script patch from David Anderson (
* * Added ability to replace strings with nothing
* * Copy changes
* * Added code to recursive_unserialize_replace to deal with objects not
* just arrays. This was submitted by Tina Matter.
* ToDo: Test object handling. Not sure how it will cope with object in the
* db created with classes that don’t exist in anything but the base PHP.
* For changes prior to v2.2.0 please refer to index.php where you will find a complete changelog. You can also browse the project on github.

To Be Done

Ensure UTF8 encoding is enforced (see comments). Added in v2.1.0
Self deletion or security system to prevent accidental security risks. Added in v3.0.0
Release CLI version for use on non-WP sites, or for other purposes (already supports use on any MySQL DB.) Added in v3.0.0
Change to GPL V3. Added in v3.0.0
Eliminate warnings and remove deprecated function calls. Added in v2.1.0
Add facility to subscribe to interconnect/it Newsletter. Added in v3.0.0
Confirm deletion has actually happened.
Add old versions for download to this page.


We’d love to get contributions, bug reports and more on the Search Replace DB public github repository. Please come on over – you’ll be more than welcome!


We’ve been asked a lot in the comments box below about accepting donations. But you can’t believe what a headache that is from an accounting and tax perspective.

Consequently all we can say is that if you wish to you can buy a personal gift for the key developers from one of the wishlists below – especially given that it’s a spare time project. If others who have contributed wish to provide us their wishlist links then we’d be more than happy to add them.

David Coveney is the project lead.
James Whitehead added the nice UI in v2.0+.
Robert O’Rourke created version 3.0.0 with its AJAX UI and massive improvements.

  • ltdl 8 / Apr / 2014 at 8:25 pm

    just used your 3.0 beta and its working like charm! thanks

  • 01e^labs 8 / Apr / 2014 at 7:47 pm

    Thanks for creating/maintaining this script! No issues have surfaced with it; it’s seemingly working flawlessly – all with a nice UI. I’ve already migrated two WP instances with this script and I’m on to #3 today!

  • Raffael Innecco 29 / Mar / 2014 at 7:10 pm

    Great tool.

  • […] a few tools which can make life easier. These included MySQL Workbench and his company’s Search/Replace […]

  • […] and updating it manually because you’ll break any serialized data. A great script for this is Search Replace DB. This script preserves serialized PHP strings when performing a search and […]

  • […] name also. It my case I didn’t require this. There is a nice free PHP script is available on or you can do it manually by […]

  • Spyros 17 / Mar / 2014 at 11:16 pm

    Hello and thank you for for sharing this usefull script.

    Can I use the v3.0.0 in a production site? Would it be safe or should I stick with the stable until v3 goes stable too? ETA for beta going stable? I see many new features that I really like on v3 and would like to start using it.


    • David Coveney
      David Coveney 19 / Mar / 2014 at 3:49 pm

      You can use it on any site but, you know, do a test run in an identically configured development environment. And take backups. This is a tool that can fritz a database very quickly, so use with care!

  • Nene 17 / Mar / 2014 at 6:19 pm

    With version 3, it’s not possible to manage different port for MYSQL:
    SQLSTATE[HY000] [2005] Unknown MySQL server host ‘localhost:3307′ (1)

    • David Coveney
      David Coveney 20 / Mar / 2014 at 11:52 am

      We’ll take a look at that, thanks.

      • Dominik 7 / Apr / 2014 at 8:22 pm

        Have you by any chance had a look to it?

        • David Coveney
          David Coveney 9 / Apr / 2014 at 2:08 pm

          Not yet I’m afraid – paying work comes first! If anybody wishes to sponsor development on this script we’ll always be happy to talk!

  • Dan Patterson 15 / Mar / 2014 at 12:50 am

    Do you have any documentation on how this works? I do not see any on this site. It sounds simple, but simple always has consequences.

  • Pěna 14 / Mar / 2014 at 11:14 am

    You’ve saved my day :)

  • […] WordPress Serialized PHP Search Replace Tool | Interconnect IT – WordPress Consultants, Web De… […]

  • Nathan 9 / Mar / 2014 at 11:17 am

    I changed my domain name on my webhosting account, and needed to change all the instances of my old domain name to my new one in my WP database. This was exactly what I needed, and worked like a charm! Thanks!!!

  • vonnie 9 / Mar / 2014 at 12:13 am

    Tool works great, just concerned about security. When I upload to document root on live server and type in I noticed my DB password is displayed in plain-text. I always press delete after running the tool; however, it still concerns me that it’s not masked with dots or something. I’m using Chrome.

  • How to move a WordPress Site | Parallel IT 7 / Mar / 2014 at 5:05 pm

    […] and set the permalink options, which regenerates a .htaccess file. 8. Use this to edit permalinks: 9. Site should be […]

  • Bernard Britten 5 / Mar / 2014 at 10:44 am

    I migrated this site to a new hosting provider, and now, though brings up the site, all subsequent pages point to“name of page” – can this tool fix it? If I get somebody like you into fix it, how much would it cost?

  • Erik 4 / Mar / 2014 at 10:21 pm


    My widgets disappear, and the arrays are not updated when I’m using the tool. The widgets remain in my site if (and only if) the search string has exactly the same length as the replace string.

    My environment is a Ubuntu 12.04 LTS LAMP-setup. I use version 3.0.0 of your otherwise fantastic tool!

    Tell me if I can assist you in any way for debugging this.


    • James R Whitehead
      James R Whitehead 7 / Mar / 2014 at 5:13 pm

      Looks like we had a problem with our unit tests that meant it showed as working when we disabled something with regard to the db encoding, when in fact it was just undoing an error in the test data. The problem would only show for various people when best guess encoding wouldn’t work. Changes have been submitted and should show immediately for the v3 zip above. If you can test it with “real world” data that would be nice.

  • petra 3 / Mar / 2014 at 5:01 pm

    When I download and unzip there is no folder ‘secret-name-please’, only a searchreplacedb.php file ..
    Than let say his databse-dummie has it set up. Is it to change the paths in a local DB or an uploaded/online DB ..?

    • D.S. 18 / Mar / 2014 at 1:45 am

      I have the same issue. Is there anybody who can help? Thanks.

  • […] Search and Replace for WordPress Databases Script […]

  • ricbax 1 / Mar / 2014 at 10:35 pm

    Having an issue when running in regex mode. I have tried various ways where a period character is involved in the search (ie. domain name)
    I cannot find a string like this: sub.domain.tld

    Could you provide an example of what goes between the / Search for … /

    Do I need to select the ismx options?


    • James R Whitehead
      James R Whitehead 4 / Mar / 2014 at 5:39 pm

      Period characters should be prefixed with an escape \.
      So replacing dev.localhost and with test.localhost should look like this:

      (www\.)?dev\.localhost =>= test.localhost

  • Migración de un sitio Wordpress 28 / Feb / 2014 at 12:16 pm

    […] Si no sabemos cómo ejecutar estas consultas SQL, también podemos utilizar esta herramienta de sustitución de strings en bases de datos. […]

  • […] files created by WordPress will not be correct. To avoid this mishap, I use a helpful script called Search Replace DB. By following the instructions in the script you can search for any string in a database and […]

  • Josephat G. M 27 / Feb / 2014 at 10:07 am

    The search and replace script has worked perfectly for me, thanks for easing my life. I managed to do what I wanted…Thumbs up…

  • […] files created by WordPress will not be correct. To avoid this mishap, I use a helpful script called Search Replace DB. By following the instructions in the script you can search for any string in a database and […]

  • Radka Kaynarova 26 / Feb / 2014 at 12:23 pm

    Thank you! Lovely and useful script!

1 33 34 35