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

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:
Table | Column | Purpose |
---|---|---|
wp_options | siteurl , home | Core URL settings |
wp_posts | guid , content | Post URLs, image links, internal references |
wp_postmeta | meta_value | Custom fields, page builders, shortcodes |
wp_usermeta | meta_value | Author 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.
- Log into your hosting control panel (e.g., cPanel or hPanel).
- Go to File Manager > Find your
wp-config.php
file. - Open it and look for: sqlCopyEdit
define('DB_NAME', 'your_database_name');
- Note your table prefix too (e.g.,
wp_
,xyz_
, etc.)

๐ป Step 2: Access phpMyAdmin and Select Your Database
- In your hosting panel, open phpMyAdmin.
- Select your WordPress database from the left sidebar.
- 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
- Browse the
wp_options
table. - Look for
siteurl
andhome
โ both should show your new domain. - 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:
- WordPress Website Development Agency
- Website Designing & Development Services
- Fix Broken Links and Improve SEO
๐โโ๏ธ 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.