How to Update WordPress URLs in the Database (SQL Query Method for Site Migrations & Fixes)

Update WordPress URLs in the SQL Database, wordpress url update query

Why You Might Need to Update WordPress URLs in Your Database Using SQL Query

Have you recently migrated your WordPress site to a new domain or switched from HTTP to HTTPS? You may notice broken links, missing images, or that your site is still loading old URLs. This happens because WordPress stores URLs throughout the database, not just in one place. find here How to Update WordPres URL in database using Sql Query:-

In this guide, weโ€™ll show you exactly how to:

  • ๐Ÿ”„ Update WordPress URL with SQL Query
  • ๐Ÿ”ง Fix broken links after migration
  • ๐Ÿงน Perform a clean search and replace
  • ๐Ÿ’ก Bulk update media, internal links, and site URLs in one go

Best of all โ€” no plugin needed. Youโ€™ll do it directly in your MySQL database using phpMyAdmin, which is efficient and powerful (but should be done carefully).

๐Ÿ” Where To Update WordPress Site URL in Database

WordPress URLs arenโ€™t stored in just one location. Here’s where they often appear:

TableColumnPurpose
wp_optionssiteurl, homeCore URL settings
wp_postsguid, contentPost URLs, image links, internal references
wp_postmetameta_valueCustom fields, page builders, shortcodes
wp_usermetameta_valueAuthor URLs, user meta

Before we begin, make sure youโ€™ve created a full backup of your database.

๐Ÿง  Step 1: Identify Your Database Name

To safely run SQL queries, you need to know your correct WordPress database name.

  1. Log into your hosting control panel (e.g., cPanel or hPanel).
  2. Go to File Manager > Find your wp-config.php file.
  3. Open it and look for: sqlCopyEditdefine('DB_NAME', 'your_database_name');
  4. Note your table prefix too (e.g., wp_, xyz_, etc.)

๐Ÿ’ป Step 2: Access phpMyAdmin and Select Your Database

  1. In your hosting panel, open phpMyAdmin.
  2. Select your WordPress database from the left sidebar.
  3. Click on the SQL tab to open the query editor.

๐Ÿงพ Step 3: Run This SQL Script to Update URLs in WordPress

Replace oldurl.com and newurl.com with your actual URLs:

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

UPDATE wp_posts 
SET guid = REPLACE(guid, 'oldurl.com','newurl.com');

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

UPDATE wp_postmeta 
SET meta_value = REPLACE(meta_value, 'oldurl.com', 'newurl.com');
  
โœ… This will:
  • Change the site URL and home URL
  • Update internal links in post content
  • Fix broken media URLs
  • Update links inside custom fields and builders

๐Ÿ“Œ If your table prefix is not wp_, update it accordingly.


๐Ÿงช Step 4: Verify That URLs Have Been Updated

  1. Browse the wp_options table.
  2. Look for siteurl and home โ€” both should show your new domain.
  3. Visit your live site and test:
    • Internal links
    • Menus
    • Images
    • Canonical tags

๐Ÿงฐ Additional Tips for WordPress URL Migrations

  • ๐Ÿงผ Use this SQL method when migrating your WordPress site to a new domain
  • โš ๏ธ Avoid using guid updates if you’re running a podcast or syndication system
  • ๐Ÿš€ For large-scale replacements, use a CLI tool like WP-CLI’s search-replace

๐Ÿ”— Internal Resource Links:


๐Ÿ™‹โ€โ™‚๏ธ FAQs

๐Ÿ”น How do I update the site URL in WordPress via MySQL?

Use an SQL script via phpMyAdmin to update values in the wp_options, wp_posts, and wp_postmeta tables. Replace old URLs with your new domain to reflect changes site-wide.

๐Ÿ”น Can I bulk update WordPress URLs via SQL?

Yes. You can use REPLACE() functions in SQL queries to search and replace URLs across multiple database tables in bulk. Always back up your database before running such queries.

๐Ÿ”น Whatโ€™s the fastest way to fix broken URLs after migration?

The SQL method shared above is the fastest and most reliable way to fix broken internal links, image paths, and media URLs in the WordPress database.

๐Ÿ”น Can I move a WordPress site to a new domain using SQL scripts?

Absolutely. The SQL queries above are commonly used after domain migrations to update internal data and avoid SEO or functionality issues.

๐Ÿ”น Is there a script to update all links in WordPress after migration?

Yes. The SQL block provided covers home, siteurl, content links, media paths, and post metadata โ€” ideal for WordPress migration change URLs.

๐ŸŽฏ Final Thoughts

Whether you’re moving to a new domain or just fixing outdated links, understanding how to update WordPress URL in the database using sql query gives you full control over your site.

At Codemonk Studio, we help businesses with WordPress migrations, database cleanups, and full-stack website support.

Need help?
๐Ÿ“ž Contact us today or request a free consultation.