← Back to All Snippets

Find and Replace URL in Entire WordPress Database via Raw SQL

⚡ Target: phpMyAdmin / SQL Console 🔒 Tested: MySQL 8.0+ / MariaDB 10.5+ 💻 Lang: SQL
⚠️ Database Table Prefix Reminder: This query uses the standard wp_ table prefix (e.g. wp_options, wp_postmeta). If your installation uses a custom table prefix (configured in wp-config.php, e.g. wp_a7b_), be sure to replace wp_ with your custom prefix before running this query.
SQL (phpMyAdmin / SQL Console)
-- Find and replace old URLs in posts, meta, options, and comments
UPDATE wp_options SET option_value = replace(option_value, 'https://olddomain.com', 'https://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'https://olddomain.com', 'https://newdomain.com');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'https://olddomain.com', 'https://newdomain.com');
UPDATE wp_posts SET guid = replace(guid, 'https://olddomain.com', 'https://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'https://olddomain.com', 'https://newdomain.com');
UPDATE wp_comments SET comment_content = replace(comment_content, 'https://olddomain.com', 'https://newdomain.com');
UPDATE wp_comments SET comment_author_url = replace(comment_author_url, 'https://olddomain.com', 'https://newdomain.com');

When migrating a WordPress site or switching domain names, execute these SQL queries in phpMyAdmin to replace old URLs across post content, excerpts, post meta, options, and comments in one pass.

← Back to All Snippets Explore Dev Tools →