How to Replace Database Entries Using phpMyAdmin
Last Updated: 2025-01-01
2 min read
After migrating a website or changing your domain name, your database may still contain old URLs, file paths, or other outdated values. phpMyAdmin provides a straightforward way to search and replace these entries across your database.
When You Need Search and Replace
Common scenarios include:
- Domain change: Replacing
http://olddomain.comwithhttps://newdomain.com - HTTP to HTTPS migration: Updating
http://references tohttps:// - Staging to production: Replacing staging URLs with production URLs
- Directory changes: Updating file paths after restructuring
Important: Always create a database backup before performing any search and replace operations. Incorrect replacements can break your website.
Method 1: Using phpMyAdmin’s Find and Replace
- Log in to cPanel and open phpMyAdmin.
- Select your database from the left sidebar.
- Click on the table you want to modify (e.g.,
wp_options,wp_posts). - Click the Search tab.
- Click Find and replace (available in newer phpMyAdmin versions).
- Configure the replacement:
- Search for: Enter the old value (e.g.,
http://olddomain.com) - Replace with: Enter the new value (e.g.,
https://newdomain.com) - Column: Select the column to search in, or choose all columns
- Search for: Enter the old value (e.g.,
- Click Go to preview matches.
- Review the matched results, then confirm the replacement.
Method 2: Using SQL Queries
For more control, use SQL commands directly via the SQL tab:
Replace in a Specific Column
UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://olddomain.com', 'https://newdomain.com')
WHERE option_value LIKE '%http://olddomain.com%';
Replace Across a Table
UPDATE wp_posts
SET post_content = REPLACE(post_content, 'http://olddomain.com', 'https://newdomain.com')
WHERE post_content LIKE '%http://olddomain.com%';
Common WordPress Tables to Update
| Table | Columns to Check |
|---|---|
wp_options | option_value (especially siteurl and home) |
wp_posts | post_content, guid |
wp_postmeta | meta_value |
wp_comments | comment_content, comment_author_url |
Important Warnings
- Serialized data: WordPress and other CMS platforms store some data in serialized format. A simple SQL
REPLACEcan break serialized strings because the character count changes. For WordPress, consider using a dedicated tool like WP-CLI’ssearch-replacecommand or the Better Search Replace plugin, which handle serialized data correctly. - Case sensitivity: MySQL
REPLACEis case-sensitive. Make sure your search term matches the exact case of the stored values. - Test first: Run a
SELECTquery with your search term before runningUPDATEto see how many rows will be affected.
Verifying the Results
After performing the replacement:
- Browse your website to check that URLs, images, and links work correctly.
- Search the database again for the old value to confirm no instances remain.
- Clear your website’s cache if you use a caching plugin.
Database search and replace is a powerful operation — take the time to back up and verify your work to avoid unintended consequences.
Tags:
cpanel
hosting
phpmyadmin
database
mysql
migration