Find and Replace in MySQL using phpMyAdmin | Blog | CampSoftware

Find and Replace in MySQL using phpMyAdmin

findandreplaceinsql

This evening, I was cleaning up the files on our websites and deleted a folder of images for our WordPress website. I had a backup of course, but the folder that I deleted was from when I was testing WordPress. Since then, I moved the WordPress files to the root directory of our website. I could have fixed it by either:

  • Upload the folder of images back to the original folder.
  • Manually fix about 80 images paths across many web pages.
  • Or do a find and replace in the SQL database that WordPress uses.

I went for the last option since I really wanted the images to point to the correct folder. I found this: phpMyAdmin search and replace

These were the steps:

  • Login to the SQL database using phpMyAdmin.
  • Open the database.
  • Find the database table.
  • Find the table field containing the text to be found and replaced.

After finding the name of the table and the name of the field, I ran the following SQL Query.

UPDATE tablename SET tablefield = replace(tablefield, "findstring", "replacestring");