更好的WordPress主题

WordPress 批量替换旧网址或内容的 Mysql 语句

摘要:操作简单,全量替换,操作前请备份

在WordPress程序的使用中,经常遇到新老域名替换等操作,通常我们会操作Mysql数据库来更快更完整的进行全量替换。

在Mysql管理界面执行以下sql语句:

注意:以下代码中的 000000 代表旧的网址, 111111 代表新的网址,都需要改成你自己的。建议操作前备份数据库以防止手残。

比如:你想把老的域名 https://themebetter.com 替换新的域名 https://www.themebetter.com

update wp_posts set `post_content`=replace(`post_content`,'000000','111111');
update wp_posts set `post_excerpt`=replace(`post_excerpt`,'000000','111111');
update wp_posts set `guid`=replace(`guid`,'000000','111111');
update wp_commentmeta set `meta_value`=replace(`meta_value`,'000000','111111');
update wp_comments set `comment_author_url`=replace(`comment_author_url`,'000000','111111');
update wp_comments set `comment_content`=replace(`comment_content`,'000000','111111');
update wp_postmeta set `meta_value`=replace(`meta_value`,'000000','111111');
update wp_usermeta set `meta_value`=replace(`meta_value`,'000000','111111');
update wp_users set `user_url`=replace(`user_url`,'000000','111111');

PS:此方法并未操作替换 wp_options 表中的数据,因为该表中存在一些非常规字符串的数据类型,所以不建议一次性操作,当然,如果你头铁想试一试,也是可以再执行以下sql语句的。此操作有风险,一些主题或插件的配置可能会失效了。

update wp_options set `option_value`=replace(`option_value`,'000000','111111');

本文属原创,转载请注明原文:https://themebetter.com/wordpress-mysql-replace.html

感觉很棒,欢迎打赏~

426 打赏
分享到:

评论 (3)

登录后评论
注:有关主题的售前售后请 提交工单
头像
wp_options 表是什么来的
头像
WordPress的配置项表,后台的很多设置都储存在这里。
头像
专业的事还是专业的人做

建站!你有充足的理由选择我们

世界上超过43%的网站是由WordPress搭建,而我们是国内最靠谱的WordPress主题开发商
在线工单