Author is Aleš Sýkora
Updated: 10. 2. 2022, Added: 10. 2. 2022
Update WordPress database URL after manual migration
Run this SQL commands in database and do not forget to change the database prefix to your one. Do this on your own risk.
UPDATE db_prefix_options SET option_value = replace(option_value, 'https://old.url/', 'https://new.url/') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE db_prefix_posts SET guid = replace(guid, 'https://old.url/','https://new.url/');
UPDATE db_prefix_posts SET post_content = replace(post_content, 'https://old.url/', 'https://new.url/');
UPDATE db_prefix_postmeta SET meta_value = replace(meta_value,'https://old.url/','https://new.url/');
UPDATE db_prefix_usermeta SET meta_value = replace(meta_value, 'https://old.url/','https://new.url/');
UPDATE db_prefix_links SET link_url = replace(link_url, 'https://old.url/','https://new.url/');
UPDATE db_prefix_comments SET comment_content = replace(comment_content , 'https://old.url/','https://new.url/');
You can also try to run this without / at the end of URL's. After you successfully run this SQL commands, go to wp-config.php file and change this lines to mach your new database credentials:
define('DB_NAME', 'databasename');
/** MySQL database username */
define('DB_USER', 'username');
/** MySQL database password */
define('DB_PASSWORD', 'password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
And do not forget to change the salt keys in wp-config too. Get new ones here: https://api.wordpress.org/secret-key/1.1/salt/