欢迎光临
我们一直在努力

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

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

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

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

比如:你想把老的域名 domain.com 替换新的域名 www.domain.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');
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《WordPress批量替换旧网址或内容的Mysql语句代码》
文章链接:http://www.zyhot.com/archives/1485.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发