{"id":1148,"date":"2024-07-07T18:38:23","date_gmt":"2024-07-07T08:38:23","guid":{"rendered":"https:\/\/tobyhuang.com\/?p=1148"},"modified":"2024-08-19T18:33:48","modified_gmt":"2024-08-19T08:33:48","slug":"migrate-the-database","status":"publish","type":"post","link":"https:\/\/tobyhuang.com\/index.php\/2024\/07\/07\/migrate-the-database\/","title":{"rendered":"Migrate the database to the new domain name to keep the web page displaying normally (wordpress)"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">After applying for a new domain name, the website content and database can be directly backed up and restored using the old website. However, due to the change in domain name, the new website address will display garbled characters when opened.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This is because the content in the database is still the old website. Just change the domain name. Assume that the old domain name is aaa.com and the new domain name is bbb.com. Use phpMyAdmin to open the database, copy this code, replace aaa.com with your old domain name, bbb.com with your new domain name, and execute go:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong><span style=\"color: #ff9900;\">SQL<\/span><\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"border-style: none;\"><code><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_options <span style=\"color: #ff9900;\">SET<\/span> option_value = <span style=\"color: #339966;\">replace(<\/span>option_value, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span> <span style=\"color: #ff9900;\">WHERE<\/span> option_name = 'home' <span style=\"color: #ff9900;\">OR<\/span> option_name = 'siteurl';<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_posts <span style=\"color: #ff9900;\">SET<\/span> post_content = <span style=\"color: #339966;\">replace(<\/span>post_content, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_posts <span style=\"color: #ff9900;\">SET<\/span> guid = <span style=\"color: #339966;\">replace(<\/span>guid, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_postmeta <span style=\"color: #ff9900;\">SET<\/span> meta_value = <span style=\"color: #339966;\">replace(<\/span>meta_value, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_comments <span style=\"color: #ff9900;\">SET<\/span> comment_content = <span style=\"color: #339966;\">replace(<\/span>comment_content, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_comments <span style=\"color: #ff9900;\">SET<\/span> comment_author_url = <span style=\"color: #339966;\">replace(<\/span>comment_author_url, 'aaa.com', 'bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><br \/><span style=\"font-family: 'andale mono', monospace;\"><span style=\"color: #ff9900;\">UPDATE<\/span> wp_postmeta <span style=\"color: #ff9900;\">SET<\/span> meta_value = <span style=\"color: #339966;\">replace(<\/span>meta_value,'aaa.com','bbb.com'<span style=\"color: #339966;\">)<\/span>;<\/span><\/code><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>After applying for a new domain name, the website content and database can be directly&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1149,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-1148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-sharing"],"_links":{"self":[{"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/posts\/1148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/comments?post=1148"}],"version-history":[{"count":20,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/posts\/1148\/revisions"}],"predecessor-version":[{"id":1221,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/posts\/1148\/revisions\/1221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/media\/1149"}],"wp:attachment":[{"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/media?parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/categories?post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tobyhuang.com\/index.php\/wp-json\/wp\/v2\/tags?post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}