How to Change WordPress URL in Database: A MySQL Tutorial Using phpMyAdmin
WordPress relies on the MySQL database to store its data, including site URLs. If you ever need to change your WordPress URL, you’ll have to make adjustments in MySQL. This article will guide you through the process, so keep reading to learn how to do it.
Download all in one WordPress cheat sheet
1. Determining the Name of WordPress MySQL Database
Skip this part if you only have one MySQL database. However, if you have multiple databases and are not sure which one is connected to your WordPress, then follow the steps below.
WordPress stores the MySQL database names and their credentials in the wp-config.php file. You can find this file in your root file directory:
- Access your hPanel and open File Manager.
- Select the domain name, then click Go to File Manager.
![hPanel dashboard, File manager highlighted](https://www.hostinger.com/tutorials/wp-content/uploads/sites/2/2023/04/hpanel-dashboard-filemanager-highlighted-1024x627.png)
- 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 is u123456789_gagap.
![wp-config file, database username highlighted](https://www.hostinger.com/tutorials/wp-content/uploads/sites/2/2023/03/filemanager-publichtml-wpconfig-dbname-1.png)
![](https://www.hostinger.com/tutorials/wp-content/uploads/sites/2/2024/06/New-WP_in-text-banner-1024x300.png)
2. Changing WordPress URLs in MySQL Database
To replace your current URL, follow these steps:
- Go to phpMyAdmin via your website’s control panel.
- The left panel lists all of your databases. Select the one connected to your WordPress site and head to the SQL tab.
![phpMyAdmin run SQL query/queries on database](https://www.hostinger.com/tutorials/wp-content/uploads/sites/2/2019/11/Screenshot-2023-01-26-at-17.46.09-1024x325.png)
- 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.
Important! Your table prefix might not be wp_. See the correct table prefix on the left panel of phpMyAdmin, and update the SQL query.
![This image shows that you have successfully changed your WordPress URLs](/tutorials/wp-content/uploads/sites/2/2016/06/sucess-messages-after-changing-wordpress-urls-e1573617184477.png)
![The new URLs in wp_options table](/tutorials/wp-content/uploads/sites/2/2016/06/new-urls-in-wp-options-table.png)
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.
Conclusion
We have just learned how to change WordPress URLs in the MySQL database using phpMyAdmin.
As we can see, all the steps above are quite straightforward. You just need to determine the correct database and then input some lines of code.
We 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!
Learn Other Advanced WordPress Techniques
How to Locate and Create the WordPress .htaccess File on cPanel and hPanel
How to Perform a WordPress Search and Replace in the Database
Basics of Using WordPress WP_Query + Examples With Code
How to Use XAMPP to Set Up a Local WordPress Site
How to Speed Up a WordPress Site
Change WordPress URL in Database FAQ
Once you know how to change WordPress URLs in your database, here are some frequently asked questions about the topic.
How Do I Change the URL in MySQL?
Changing the URL in MySQL requires some technical knowledge. First, you’ll need to open the database where your URL is stored, often in the data folder within your MySQL installation directory. Then, use a text editor to find and replace all instances of the old URL with the new one.
How Do I Connect My WordPress Website to MySQL Database?
First, log in to your hosting account and launch phpMyAdmin. There, click on the Import link from the top menu and then the Choose file button. Select your WordPress database to connect the two.
Can I Change My WordPress Database Name?
Yes, it is possible to change your WordPress database name. Once you access the phpMyAdmin from your hosting account, click on the Operations tab. Under Rename database to, enter the new name and click Go.
Comments
April 04 2018
Hi, I followed your instructions but it seems my new site still redirects to the old URL. I've checked the wp_options as you said and it's all pointing to the new. Very weird. Pat
April 28 2018
Hey Pat, Do you have any kind of caching plugin installed? if so, try to clear cache or disable the plugin
October 25 2019
This worked wonderfully well for me. Thank you!
January 01 2020
helpful post for a developer, thanks!
February 08 2020
thanks for share this article
June 20 2020
Excellent and well documented solution! Thanks
June 26 2020
What if we don't have any table of wp_options ?
July 07 2020
Hey Christine! :) Perhaps you can check if you are using a custom prefix for the tables? In wp-config.php you can change the prefix of the tables, so if you set it to for example blog, your table would be blog_options. Additionally, make sure to select "Show ALL" instead of "Show 25" which is the default value for the shown tables in phpMyAdmin :)
August 01 2020
Hi, I own a website hosted in the main domain, and the blog hosted in a subdomain. I want to change the blog URL, so it would have the same domain as the site. Do you think it will work if I use this tutorial? Or it might go wrong since the new domain already exists? Thank you for your attention, Laura
November 06 2020
Hey Laura. If you want to make the subdomain have the exact same URL as the main domain, that would cause problems, and I'd advise against it :)
August 04 2020
What about serialized data? If the URLs are not the same length, just replacing URLs might be a problem...
November 06 2020
Hey Larry. This tutorial is more about the main website URL, not about URLs within the website (directories, posts, etc). I am afraid Serialized Data in WordPress is a bit out of my scope of knowledge so I'd recommend checking the great forum at www.stackoverflow.com which will surely offer some help on the topic! :)
August 10 2020
Hello, I have followed the process but now it sending Server IP not found error could you please help/?
November 06 2020
Hey Jerry! I Can't see the error here but make sure the domain (URL) you've used is an active domain and is pointing correctly. Additionally make sure the domain is spelled correctly. For instance, if you used www.domain.com and your domain doesn't have WWW DNS record, the server IP won't be reached.
September 06 2020
Replacing domains in your database in tables that uses the PHP serialize function to store its data, results in a corrupted database. A much simpler method of replacing all domains at once, and repairing these serialized structures is by using a tool like https://wordpress-search-replace.io/
November 11 2020
Hey André. Great input - you can definitely achieve that with a tool such as search and replace. That being said - even the official WordPress guide mentions changing the URL via the database, so I believe it's quite rare that a database gets corrupted when doing this.
October 12 2020
Hello Excellent Information, I am highly recommended this blog. For these reasons, I have tried to find out a solution but, I don't get a very good solution. but I have got the right solution from here. Thanks
February 02 2021
Hi, Oliur! Happy it worked out ;)
October 20 2020
Worked great! thanks.
January 21 2021
This post was extremely useful. Very Thanks.
January 22 2022
This saved my ass thanks!
February 08 2024
Thank you to Hostinger and the author of this article
February 20 2024
You're very welcome! If you have any questions or need further assistance, please don't hesitate to reach out ?
July 18 2024
I'm so grateful for finding this post. I thought that I had screwed up my entire website, but that didn't happen because of you guys. Thank you so much.
July 24 2024
Awesome to hear that!