There are two ways to replace a domain name in the database while migrating a website. The first way is to use the search and replace function in your database software. The second way is to create a new record for the new domain and then delete the old one.
The search and replace function can be used by following these steps:
– Open your database software,
– Open your website’s database,
– Click on “Find & Replace” tab,
– Type in “olddomainname” into field for “Find what:” and type “newdomainname” into field for “Replace with:”
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
Finally update your WordPress config file to reflect the new database, wp-config.php” which should be in your web document root – change, databasename, username, password and host values:
define('DB_NAME', 'databasename');
/** MySQL database username */
define('DB_USER', 'username');
/** MySQL database password */
define('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
Now everything should link up perfectly.
Hawk Tech develops & designs your website and helps you to grow your business online. We also provide SEO, Lead Generation, and Branding that improve your online existence.
The Hawk Tech will send you our latest blogs related to the technology and our updates.