WordPress uses MySQL database to store all its data: posts, pages, profiles, configuration. If you moved your WordPress website to a different folder or your domain name has changed, it is necessary to change WordPress URLs in various MySQL database tables.
Table of Contents
What you’ll need
Before you begin this guide you’ll need the following:
- Access to the control panel of your hosting account.
- Basic understanding of phpMyAdmin.
Step 1 — Determining Name of WordPress MySQL Database
You can skip this step if you have only one MySQL database. However, if you have more than one and not sure which database is connected to WordPress, you need to determine the name of MySQL database. WordPress stores MySQL database name and credentials in wp-config.php file. You can find wp-config.php in your root WordPress file directory. Use File Manger of FTP client to access this file.
Open wp-config.php file and search for
In this case name of our MySQL database is ptsk6_wp649.
Step 2 — Entering phpMyAdmin
You can find phpMyAdmin under databases section in your control panel.
Step 3 — Selecting Appropriate Database.
On the left side of phpMyAdmin you can see all existing databases. Select MySQL database which is connected to your WordPress website.
Step 4 – Formatting SQL Query
Press on SQL section in phpMyAdmin and enter the following code:
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 code will replace all instances of oldurl.com to newurl.com. For example if your current WordPress address is oldurl.com, it will be changed to newurl.com.
IMPORTANT! Do not forget to replace oldurl.com with your current WordPress address and newurl.com with your new WordPress address.
IMPORTANT! Sometimes table prefix can be different than wp_. If you get error messages saying that tables wp_options, wp_posts, wp_posts and wp_postmeta cannot be found, check table prefix and update SQL query code. You can see table prefix on the left side of phpMyAdmin, under your WordPress database:
In this example table prefix is wpqc_.
Step 5 – Running SQL Query
Once you replaced URLs and table prefix you can run your query. In order to run it, press GO button which is located on the bottom right.
Step 6 – Verifying The Successful Change of URLs
If the query was executed successfully, you will see a green success message:
Note that number of rows will be different for each WordPress website.
In order to verify changes open wp_options table and check your home and siteurl values. You should see new WordPress urls from the SQL query. In this example WordPress urls were changed to newurl.com
If you get errors and query is not executing, check your code for syntax errors and make sure you are using the correct table prefix. If you still get any errors, simply contact support staff of hosting for assistance.
You just learned how to change WordPress URLs in MySQL database using phpMyAdmin. If you have not yet moved WordPress to a different folder, you can do so by following this tutorial.