How to Change WordPress URL in MySQL Database Using phpMyAdmin?

Do you need to transfer a WordPress website from one domain to another? Did you create a WP website on a temporary domain either locally or on a staging domain URL? You need to migrate the WordPress website to the new URL, which needs changing the old URL with the actual one.

When migrating a WordPress site to a new domain or changing the site’s URL, updating the database is a crucial step when changing the website domain URL.

There are primarily two approaches to migrating a WordPress website from one domain to anther.

  • Manually transfer files and change URL in MySQL database using phpMyAdmin (SQL Terminal Command)
  • Using WordPress plugins to prepare files and database for transfer

How to Change WordPress URL in MySQL Database Using phpMyAdmin for Migrating to New Website Address?

Let’s learn into the process of changing WordPress URLs directly in the MySQL database using phpMyAdmin. Follow these instructions carefully to ensure a smooth transition to your new URL.

1. Access phpMyAdmin

First, log into your web hosting account and navigate to phpMyAdmin, which allows you to manage your database directly using a graphical interface.

2. Select the Correct Database

In phpMyAdmin, locate and select the database used by your WordPress installation that you want to migrate to another domain/URL. You can find the database name in the wp-config.php file in your WordPress website directory.

3. Identify Your Table Prefix

WordPress tables typically have a prefix, such as wp_. However, this prefix may vary if you changed it during the installation for security reasons. Check the left panel in phpMyAdmin to confirm your table prefix.

4. Run SQL Queries

Replace oldurl.com with your current WordPress address and newurl.com with your new WordPress address in the following SQL queries. Adjust the table prefix (wp_ in this example) if necessary.

SQL Command
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');

To execute these queries, copy and paste each line into the SQL tab in phpMyAdmin and press “Go”.

5. Verify the Changes & Export

After running the queries, it’s essential to verify that the changes were successful:

  • Open the wp_options table.
  • Check the option_value for siteurl and home. They should display your new URL.

Once the URL has been changed, you can then locate the Export tab in phpMyAdmin while the database is selected. Export the entire database for migrating to another web server or hosting. Make sure that you are not within any table or higher as that would export the respective table or all databases instead.

Alternatively, you can also use the Backup tool available in your web hosting dashboard to export the database. To keep the database file size low, you can choose an archive format when exporting the database using phpMyAdmin.

Now, you can use the file browser tool in your hosting dashboard to create a ZIP archive to export your website files. Go to the root directory where your website files are located (generally public_html). Now, select all the files and folders, and select the Compress option to create a ZIP archive. You can now download this ZIP folder. To create a backup of files, you can also use the Backup tool and create a partial backup of the Home directory.

6. Migrate Your Website

Now, it’s time to migrate your website to another web hosting server. Upload the file ZIP archive of your website. Create a new database with a user with all privileges. Go to phpMyAdmin and select the new database, go to the Import tab and import the database backup created. Make sure to change the wp-config.php file in the root directory of your website. You need to change the database name, username and password to match with the new database.

7. Troubleshoot Errors

If you encounter any error messages or if the queries do not execute properly, ensure the following:

  • Check for syntax errors in the SQL code.
  • Verify that you are using the correct table prefix.
  • If problems persist, contact your hosting support for further assistance.