How to Change WordPress URL in Database: A Step-by-Step Tutorial Using phpMyAdmin

How to Change WordPress URL in Database: A Step-by-Step Tutorial Using phpMyAdmin

Changing the URL of your WordPress site may be necessary during website migration or when transitioning from a development environment to a live server. This tutorial will guide you through the process of changing WordPress URLs in the MySQL database using phpMyAdmin. Follow these steps carefully to ensure a smooth transition.

Step 1: Determine the Name of Your WordPress MySQL Database

Before making any changes, you need to identify the name of your WordPress MySQL database. This information is crucial for accessing the correct database in phpMyAdmin.

  1. Login to your hosting control panel.
  2. Locate and access the “Database” or “MySQL Databases” section.
  3. Look for the database associated with your WordPress installation. Make note of the database name.

OR

  1. Login to your hosting control panel.
  2. Open File Manager.
  3. Open wp-config.php and search for DB_NAME. The value of this parameter is your database name.

Step 2: Open phpMyAdmin and Navigate to the WordPress Database

Once you have the database name, it’s time to open phpMyAdmin and locate the WordPress database.

  1. Log in to your hosting account.
  2. Find and open phpMyAdmin from the control panel.
  3. On the left-hand side, you’ll see a list of databases. Click on the database corresponding to your WordPress site.

Step 3: Changing WordPress URLs in MySQL Database via Query or Table Update

Now that you are in the correct database, you can proceed with changing the URLs.

Option 1: Using SQL Queries

  1. Navigate to the “SQL” tab in phpMyAdmin.
  2. Execute the following SQL queries, replacing `oldurl.com` and `newurl.com` with your old and new URLs:


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

Important! Your table prefix might not be wp_. See the correct table prefix on the left panel of phpMyAdmin, and update the SQL query.

Click “Go” to execute the queries.

Option 2: Update URLs Manually in wp_options Table

  1. Click on the “wp_options” table.
  2. Look for rows with the “option_name” values “siteurl” and “home.”
  3. Click the “Edit” button for each of these rows.
  4. Update the “option_value” field with your new URL.
  5. Click “Go” to save the changes.

Conclusion:

Congratulations! You have successfully changed the WordPress URLs in the MySQL database using phpMyAdmin. Make sure to test your site thoroughly to ensure all links and resources are loading correctly with the new URL.

Note: Always perform a backup before making any changes to your database to avoid potential data loss.