If you've moved your website to a new domain, switched from http to https, or restored a backup taken from a staging site, old text (usually your old domain name or URL) is often still stored inside your database. The safest way to fix this across many rows at once is to run a search and replace directly in your database through phpMyAdmin, rather than editing files one by one.
When You'd Need to Do This
- You forced your website to https and want to update old http links stored in page content or settings.
- You moved your website to a new domain name and old links throughout the site still point to the previous one.
- You restored a backup that was taken from a staging or temporary address, and it still references that address.
- You're standardizing on www or non-www and need stored links to match.
Before You Start
Always back up your database before running a search and replace. A find-and-replace query changes many rows at once and can't be undone with a click. See How to Back Up a Single MySQL Database first if you haven't already.
Opening phpMyAdmin
In cPanel
- Log in to your cPanel account.
- Under the Databases section, click phpMyAdmin.
- Select your database from the list on the left.
In DirectAdmin
- Log in to your DirectAdmin account.
- Click MySQL Management, then find your database in the list.
- Click the phpMyAdmin icon next to it to open the database.
Once you're inside phpMyAdmin, the rest of the process is the same regardless of which control panel you use.
Running a Search and Replace Query
phpMyAdmin's Search tab can look for text across a table, but it doesn't reliably replace text inside every row type. For a proper find-and-replace, use the SQL tab instead.
- With your database open, click the SQL tab at the top.
- Click on the specific table in the left sidebar if you want to target just that table.
- Enter a query in this form, replacing the table name, column name, old text, and new text with your own:
UPDATE table_name SET column_name = REPLACE(column_name, 'old-text', 'new-text'); - Click Go to run the query.
- Repeat for each table and column that contains the old text. Common places to check are tables that store page content, links, and site settings.
This method works well for plain text fields, but it can corrupt serialized data, a format some applications (including WordPress) use to store arrays of settings as a single long string with a recorded length. Replacing text inside a serialized string without updating that stored length breaks it. See the section below if your site is built on WordPress.
If You're Using WordPress
WordPress stores your site's web address and many settings as serialized data in the wp_options table, along with references to it in wp_posts and other tables. Running a plain REPLACE() query on these tables will likely break your site.
Instead, use a tool built to handle serialized data safely:
- A dedicated search-and-replace plugin installed from your WordPress dashboard. This is the simplest option if you don't have command-line access.
- The search-replace command in WP-CLI, if you have SSH access to your hosting account. See How to Enable and Use SSH Access on Your Hosting Account to set this up. WP-CLI updates serialized data correctly and works well on larger sites.
Whichever method you use, back up your database first and double-check the exact old address you're replacing, including whether it included www or https, so you don't miss any references.