Updating WordPress URLs Without Plugins: A Direct SQL Approach

Updating WordPress URLs Without Plugins: A Direct SQL Approach

Changing the URLs of a WordPress website is crucial when moving to a new domain or transitioning from HTTP to HTTPS. Below is a step-by-step guide using SQL commands to update all necessary database entries.

Step 1: Backup Your Database

Before making any changes, always back up your database:


    mysqldump -u username -p database_name > backup.sql

Step 2: Update WordPress Database URLs

Run the following SQL commands to replace the old URL with the new one. Replace oldurl with your current domain and newurl with the new domain.

Update GUIDs in wp_posts

UPDATE wp_posts SET guid = REPLACE(guid, 'oldurl', 'newurl') WHERE guid LIKE 'oldurl/%';

Update Site URL and Home URL in wp_options


    UPDATE wp_options SET option_value = REPLACE(option_value, 'oldurl', 'newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

Update URLs in Post Content


    UPDATE wp_posts SET post_content = REPLACE(post_content, 'oldurl', 'newurl');

Update URLs in Post Meta Data


    UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'oldurl', 'newurl');

Update URLs in Yoast SEO Data (Only if you are using Yoast SEO Plugin)


    UPDATE wp_yoast_indexable SET permalink = REPLACE(permalink, 'oldurl', 'newurl');

Step 3: Clear Cache and Flush Permalinks

After running the queries, clear your cache and refresh permalinks:

  1. Go to WordPress Admin > Settings > Permalinks
  2. Click Save Changes to regenerate permalinks.

Step 4: Test Your Website

  • Visit the site and check if all URLs are updated correctly.
  • Verify links, images, and functionality.

Why This Approach is Better Than a Plugin

While plugins can make URL changes easier, this direct SQL approach has several advantages:

  • Faster: Running SQL queries directly on the database is much faster than relying on a plugin, especially for large sites.
  • No Extra Load: Plugins can add overhead, slowing down your website. This method bypasses that concern by updating the database directly.
  • More Control: Using SQL gives you full control over the process, ensuring that no unnecessary changes are made.
  • No Dependency: With this approach, you are not relying on third-party plugins, which may become outdated or conflict with other plugins in the future.

Conclusion

Using these SQL commands, you can efficiently update URLs in a WordPress database. Always take a backup before making changes to prevent data loss.

About Author

Shiva Sheshendra

Senior Web Developer / Senior PHP Developer / Full Stack Developer

“Web Development, Website Maintenance, Server Management, On-Page SEO, Security, and Malware Removal”

Connect with Developer View Portfolio

Request A Callback

Ready to unlock your digital potential?
Request a callback to learn how we can help

© All rights reserved 2025 codenbrand. Designed and Developed by shivafeb17

WhatsApp Icon