phpMyAdmin SQL Search and Replace: Safer WordPress Updates

phpMyAdmin lets you run SQL queries directly against a MySQL or MariaDB database. One common use is finding and replacing a URL or text string in a specific table column. This can be fast, but a broad UPDATE query changes data immediately, so first preview the matches and create a verified database backup.

This guide shows the basic SQL REPLACE() function, a safer preview-first workflow, and an example for WordPress post content. For a whole-site WordPress migration, prefer WP-CLI's serialized-data-aware search-replace command or a reputable migration tool rather than running blind replacements across arbitrary tables.

What are SQL and MySQL?

SQL (Structured Query Language) is used to query and modify relational databases. MySQL and MariaDB are database management systems that use SQL. WordPress commonly stores posts, settings, and other site data in a MySQL-compatible database.

How to use phpMyAdmin for SQL search and replace

SQL search and replace example in phpMyAdmin

  1. Create a fresh database backup and make sure you know how to restore it.
  2. Open phpMyAdmin from your hosting control panel and select the correct database.
  3. Confirm the table and column you intend to change. WordPress installations do not always use the default wp_ table prefix.
  4. Click the SQL tab and run a read-only SELECT query to preview affected rows.
  5. Review the results carefully. Only run an UPDATE query after confirming the search string and replacement are correct.

Preview matches before replacing text

For a generic table and column, replace the example identifiers and strings with your own. Table and column names must be valid identifiers in your database.

SELECT id, tablefield
FROM tablename
WHERE tablefield LIKE '%findstring%';

This is a template, not a query to paste unchanged. If the table has no column named id, select its actual primary key instead. Check the results before proceeding.

Run the SQL search-and-replace query

Once you've confirmed the matches and backed up the database, the basic pattern is:

UPDATE tablename
SET tablefield = REPLACE(tablefield, 'findstring', 'replacestring')
WHERE tablefield LIKE '%findstring%';

Replace tablename, tablefield, findstring, and replacestring with the actual table, column, old text, and new text. The WHERE clause limits the rows considered to those containing the old string. SQL string matching and case behavior depend on the database column's collation, so verify your intended matches.

Example: replace text in WordPress post content

To replace an old domain in WordPress post content, first preview the posts that contain it. The example below assumes the default wp_ prefix; use your actual table prefix.

SELECT ID, post_title
FROM wp_posts
WHERE post_content LIKE '%coolstuff.com%';

If the preview is correct, back up the database and run:

UPDATE wp_posts
SET post_content = REPLACE(post_content, 'coolstuff.com', 'lancelhoff.com')
WHERE post_content LIKE '%coolstuff.com%';

This only changes the post_content column in the posts table. It does not automatically update links in post metadata, WordPress options, widgets, plugin tables, or other locations.

Important cautions

  • Back up first. SQL updates can affect many rows at once and may be difficult to undo without a backup.
  • Do not assume the table prefix. Confirm your database's actual table names before running the example.
  • Be careful with serialized data. Plain SQL replacements can corrupt PHP-serialized values in options or metadata by invalidating stored string lengths. Use a serialized-data-aware tool for those fields.
  • Use exact search strings. Replacing a short or common phrase can alter unrelated content.
  • Understand the scope. The query changes only the table and column named in the statement.

A safer option for WordPress-wide replacements

For a domain migration or a replacement that spans multiple WordPress tables, use WP-CLI's search-replace command with --dry-run first, or use a trusted migration plugin that supports serialized data. See the companion guide: WordPress search and replace: URLs and text safely.

Frequently asked questions

Does SQL REPLACE change every occurrence in a database?

No. It replaces occurrences within the value of the column specified in the query, and only in the rows selected by the query. Other tables and columns are not changed automatically.

Can I use this query for a full WordPress domain migration?

A simple query is not ideal for a whole-site migration. WordPress data may include serialized values, and URL references can exist in many tables. Use WP-CLI's search-replace command or a migration tool that handles serialized data.

Why should I run SELECT before UPDATE?

A SELECT query lets you inspect which rows match before changing anything. It helps catch an incorrect table, column, or search string before the update is applied.