EnsureDomains
Free tool

Change WordPress URL Using MySQL

Generate the exact MySQL UPDATE queries to move your WordPress site to a new URL — across options, posts, and metadata. Fill in your prefix and URLs, copy the SQL, and run it in phpMyAdmin. Free, private, and assembled entirely in your browser.

All free tools

Found in wp-config.php as $table_prefix. Defaults to wp_.

Back up your database before running these queries. These statements rewrite data in place and cannot be undone. Export a full backup first (phpMyAdmin → Export, or your host's backup tool).

Generated MySQL
-- Site address & WordPress address (Settings → General)UPDATE `wp_options` SET option_value = REPLACE(option_value, 'https://old-domain.com', 'https://new-domain.com') WHERE option_name IN ('home', 'siteurl');
-- Post & page GUIDsUPDATE `wp_posts` SET guid = REPLACE(guid, 'https://old-domain.com', 'https://new-domain.com');
-- Post & page content (links, embedded images)UPDATE `wp_posts` SET post_content = REPLACE(post_content, 'https://old-domain.com', 'https://new-domain.com');
-- Post & page excerptsUPDATE `wp_posts` SET post_excerpt = REPLACE(post_excerpt, 'https://old-domain.com', 'https://new-domain.com');
-- Post meta (custom fields, page builders)UPDATE `wp_postmeta` SET meta_value = REPLACE(meta_value, 'https://old-domain.com', 'https://new-domain.com');
-- Term metaUPDATE `wp_termmeta` SET meta_value = REPLACE(meta_value, 'https://old-domain.com', 'https://new-domain.com');
-- User metaUPDATE `wp_usermeta` SET meta_value = REPLACE(meta_value, 'https://old-domain.com', 'https://new-domain.com');

A note on serialized data. A raw REPLACE can corrupt serialized values — PHP arrays and objects (common in theme options, widgets, and page-builder layouts) that store the byte length of each string. Changing a URL changes that length, breaking the record. If your URLs may live inside serialized option or meta values, use wp search-replace (WP-CLI) or the Better Search Replace plugin, which rewrite serialized data safely.

Every query is generated locally in your browser. Your prefix and URLs are never uploaded, logged, or stored.

When to use it

When you'd change your WordPress URL in the database

WordPress stores its address in several places, not just one settings field. Editing the database directly is the right tool whenever the URL has to change everywhere at once — or when you can't reach the dashboard to change it the normal way.

Migrated to a new domain

You moved the site from one domain to another and every internal link, image, and the admin login still point at the old address.

Moved from staging or localhost

A site built on staging.example.com or http://localhost needs its URLs rewritten to the live domain before launch.

Switched http → https

After installing an SSL certificate, mixed-content warnings linger because the database still references http:// URLs.

Locked out of wp-admin

A wrong Site Address in Settings → General can redirect you in a loop, so you can no longer reach the dashboard to fix it.

White screen after a URL change

An accidental edit to the home or siteurl value broke the front end, and the database is the only reliable place to correct it.

Step by step

How to change your WordPress URL with MySQL

Five steps from backup to verification. Follow them in order — the backup and the final permalink flush are the two people skip and regret.

  1. Step 1

    Back up your database

    Before touching anything, export a full copy of the database. In phpMyAdmin, select your database, open the Export tab, choose the Quick method with SQL format, and download the file. If your host offers one-click backups, take one as well. These UPDATE queries cannot be undone — a backup is your only way back.

  2. Step 2

    Find your table prefix

    WordPress prefixes every table, by default wp_. If yours differs, open wp-config.php and read the $table_prefix value — for example $table_prefix = 'wp_';. Enter that exact prefix in the generator so the queries target the right tables.

  3. Step 3

    Determine the exact old and new URLs

    Write both URLs precisely: include the protocol (http or https), the full domain, and the same www (or non-www) form your site actually uses. Do not add a trailing slash. A mismatch — say https://www. vs https:// — means REPLACE finds nothing and the change silently does nothing.

  4. Step 4

    Run the SQL

    In phpMyAdmin, click your database in the left sidebar, open the SQL tab, paste every generated statement, and press Go. Adminer works the same way: select the database and use the SQL command box. Run all statements together so the options table and content stay in sync.

  5. Step 5

    Verify and flush

    Clear any page, object, or CDN cache, then load the front end and log in. Confirm Settings → General shows the new URL, then open Settings → Permalinks and click Save Changes (without editing anything) to flush rewrite rules. Click through a few pages to check links and images resolve.

A word on serialized data

WordPress and its plugins often store settings as serialized data: PHP arrays and objects packed into a single string that records the exact byte length of every value it contains — for example s:19:"https://old-site.com". When a blunt SQL REPLACE swaps the URL for one of a different length, that 19 no longer matches, and PHP can no longer read the record. Widgets vanish, theme options reset, page-builder layouts break.

If your URLs only appear in plain content — post bodies, the home and siteurl options, image links — the queries above are safe. But if they may be buried in serialized option or meta values, use a serialization-aware tool instead:

  • WP-CLI: wp search-replace 'https://old' 'https://new' — add --dry-run first to preview the count.
  • Better Search Replace plugin — a UI alternative when you don't have terminal access; run its dry run before committing.
Alternatives

Other ways to change your WordPress URL

MySQL isn't the only path. Here's how the common methods compare — and where each one falls short.

Settings → General

Pros
Quickest path when you can still reach the dashboard. No code or database access needed.
Cons
Only updates home and siteurl — it leaves old URLs baked into post content, images, and meta. You stay locked out if the wrong URL is what broke admin access.

WP_HOME / WP_SITEURL in wp-config.php

Pros
Forces the site and admin URLs via constants — perfect for breaking a redirect loop and regaining access fast.
Cons
Overrides, rather than fixes, the database. The Settings fields become read-only, and content URLs are still unchanged. Best as a temporary unlock.

functions.php snippet

Pros
A temporary update_option('home', ...) / update_option('siteurl', ...) pair restores admin access without database tools.
Cons
Must be removed immediately after one load, or it overwrites the value on every request. Like the constants, it only touches two options.

WP-CLI search-replace

Pros
The safest full-site rewrite: wp search-replace handles serialized data correctly and covers every table. Supports a --dry-run preview.
Cons
Requires SSH or terminal access to the server, which not every shared host provides.

Change WordPress URL: questions, answered

Why change the WordPress URL using MySQL?

Editing the database directly is the most reliable way to change a site's URL when you can't reach wp-admin, or when old URLs are scattered across posts, images, and metadata that the Settings screen never touches. It also works on staging-to-live and http-to-https moves where every reference has to be rewritten at once.

Will this break my images or internal links?

No — it fixes them. The generated queries rewrite URLs inside post content, GUIDs, excerpts, and meta, so links and image src paths point at the new domain. The most common cause of broken images is missing one of these tables, which is why the tool covers all of them.

What about serialized data?

A plain SQL REPLACE can corrupt serialized values — PHP arrays and objects that store the byte length of each string, common in theme options, widgets, and page builders. If your URLs may live inside serialized data, use WP-CLI's wp search-replace or the Better Search Replace plugin, which adjust those lengths automatically.

Do I need to update permalinks after running the queries?

Yes. After the URL change, go to Settings → Permalinks and click Save Changes without editing anything. This flushes WordPress's rewrite rules and prevents 404s on inner pages.

How do I go from http to https?

Install your SSL certificate first, then set the old URL to your http:// address and the new URL to the matching https:// address and run the queries. This clears most mixed-content warnings by rewriting database references to the secure protocol.

What is the table prefix and where do I find it?

WordPress adds a prefix to every table name, wp_ by default. Your real prefix is defined in wp-config.php as $table_prefix. If you changed it during install (e.g. wpab_), enter that value in the generator so the queries target the correct tables.

Is my data private?

Yes. The generator runs entirely in your browser. Your table prefix and URLs are never uploaded, logged, or stored — the SQL is assembled locally and only you ever see it.

What if I'm locked out of wp-admin?

A wrong Site Address often causes the lockout. Running the options query here resets home and siteurl directly in the database, which usually restores access immediately. Defining WP_HOME and WP_SITEURL in wp-config.php is a fast temporary alternative.

Will this affect my SEO or redirects?

Changing the URL inside the database doesn't create redirects on its own. When you move to a new domain, also add 301 redirects from the old domain to the new one (at the server or DNS level) so search engines and existing links follow you and rankings carry over.

Do I really need to back up first?

Yes — without exception. UPDATE queries overwrite data permanently with no undo. A full export taken right before you run them is the difference between a five-minute fix and a lost website.

Does the order of the queries matter?

Not for correctness — each statement targets a different column. Run them together in one batch so the options table and your content are updated in the same pass and the site is never left half-migrated.

Tired of editing the database by hand?

Managed WordPress hosting from EnsureDomains handles migrations, staging, automatic backups, and SSL for you — so a domain move is a guided step, not a SQL query. Or keep exploring our free, no-signup developer tools.