How to Change WordPress URLs Using phpMyAdmin in MySQL Database
After migrating a WordPress site to a new URL either to a live production site or a testing development server, the new URL strings in the MySQL database need to be changed and updated in the various MySQL database tables.
This method just uses the whole MySQL database rather than a WordPress export/import from within and is best suited for a straight swap. So you would copy all the WordPress files/folders to the new destination, set the correct ownership to those files
WordPress uses MySQL database to store all its data, including site URLs. So if for some reason you need to change your WordPress URL, it’s necessary to tweak some data in MySQL. Keep reading to know how to do it!
1. Determining the Name of WordPress MySQL Database
You can skip this part if you only have one MySQL database. However, if you have multiple databases and not sure which one is connected to WordPress, then follow the steps below.
WordPress stores MySQL database name and its credentials (user name & DB Password) in the wp-config.php file. You can find this file in your root file directory:
- Access your CPanel and open File Manager or access using FTP.
- Select the domain name, then click Go to File Manager
3. Open wp-config.php and search for DB_NAME. The value of this parameter is your database name. For instance, the name of our MySQL database “Give new DB Name”
2. Changing WordPress URLs in MySQL Database
Replacing your old URL is not difficult at all. Here’s what you need to do:
- Go to phpMyAdmin via your website control panel.
- The left panel list all of your databases. Select the one connected to your WordPress site and head to the SQL tab
Enter the following SQL query
- 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’);
Replace oldurl.com with your current WordPress address and newurl.com with your new WordPress address.
Your table prefix might not be wp_. See the correct table prefix on the left panel of phpMyAdmin, and update the SQL query.
- Press Go. You will see success messages along with the number of changed rows. Note that the number of rows will be different for each WordPress website.
The last thing we need to do is verify the changes. Open the wp_options table and check the option_value of siteurl and home. You should see your new URL.
If you get error messages and the queries are not executing, check your code for syntax errors and make sure you are using the correct table prefix. Contact the hosting support for further assistance if the error persists.
I hope this tutorial can give you clear guidance on how to change WordPress URLs in the MySQL database. Kindly leave any questions you have below!
Note that there are additional concerns with other methods, as references to the old URL will persist in the database. Two known issues that users face frequently are:
- Old URLs in widgets and menus: The old URL can exist not only in posts but also in widgets and menus.
- Broken Image and Video links: If you have successfully replaced the site URL, it is possible that the images are not functioning properly. This can cause issues with page display if you do not update image URLs.
The URLs are stored in many database tables and you can change them manually. The URLs for custom menu items are present in the meta_value field in the wp_postmeta table. The image URLs are present inside the posts_content field in the wp_posts table. For the old link manager, the image URLs are present in the link_image fields in the wp_links fields. You need to be careful in what you replace. So be sure you are aware of the meaning of the field before you change it. Here’s a quick list of places where you can find the URL:
- Inside posts and pages: “posts_content” field in the “wp_posts” table
- The old link manager: “link_url” and “link_image” fields in the ‘wp_links” table
- URLs of Custom Menu items: “meta_value” field in the “wp_postmeta” table
- Options or themes and plugins: “option_value” field in the “wp_options” table
- URLs inside comments: “comment_content” field in the “wp_comments” table
You can update old URLs in the database by making the change in each of the above-mentioned tables and fields. But this method is cumbersome and highly time-consuming. Basically, we choose to implement tools and plugins which are easy, safe and quick to use.