找回密码
 加入网盟
分割线
官方精品推荐
老牛的一个网站数据量较大,接近八万条数据,需要替换所有内容中的部分内容
最快方法当然是在phpmyadmin使用sql语句来完成,替换前务必备份数据库,以免出现失误
替换语句:
  1. UPDATE wp_posts SET post_content = REPLACE( post_content, 'old content A', 'new content B' )
复制代码


解释:更新数据库中wp_posts表post_content字段的内容"old content A"为"new content B"(不包含双引号"")

WordPress常用SQL语句
筛选自定义meta的YouRUrl_value包含.pdf的内容,替换为.rar
  1. UPDATE `wp_postmeta` SET `meta_value` = REPLACE( meta_value, '.pdf', '.rar' ) WHERE `meta_key` = 'YouRUrl_value' AND `meta_value` LIKE '%.pdf%'
复制代码

查找wordpress自定义字段yourmeta中包含aaa.com的记录

  1. select * from wp_postmeta WHERE `meta_key` = 'yourmeta_value' AND `meta_value` LIKE '%aaa.com%'
复制代码


建立一张表来存储查找的记录

  1. create table a_temp as select * from wp_postmeta WHERE `meta_key` = 'yourmeta_value' AND `meta_value` LIKE '%aaa.com%'
复制代码

在刚才新建的表中插入包含bbb.com的记录

  1. insert into a_temp(meta_id,post_id,meta_key,meta_value) select * from wp_postmeta WHERE `meta_key` = 'xzy1url_value' AND `meta_value` LIKE '%bbb.com%'
复制代码

mysql删除斜杠/之前的内容.如果有多个斜杠/,就多执行几次

  1. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1)
复制代码

mysql在meta_value字段原有的字符串前插入字符串aaa
  1. update a_temp SET meta_value= CONCAT('aaa',meta_value)
复制代码

mysql在meta_value字段原有的字符串后插入字符串aaa
  1. update a_temp SET meta_value= CONCAT(meta_value,'aaa')
复制代码

mysql字段的字符串中格式化
  1. UPDATE a_temp SET meta_value = REPLACE( meta_value, ' ', '' )
  2. UPDATE a_temp SET meta_value = REPLACE( meta_value, '.', '_' )
  3. UPDATE a_temp SET meta_value = REPLACE( meta_value, '_rar', '.rar' )
  4. UPDATE a_temp SET meta_value = REPLACE( meta_value, ',', '' )
复制代码
  1. UPDATE `wp_postmeta` SET `meta_value` = REPLACE( meta_value, '.pdf', '.rar' ) WHERE `meta_key` = 'yoururl_value' AND `meta_value` LIKE '%bbbb.com%'
复制代码

筛选yoururl_value字段里包含bbbb.com内容的数据
  1. select * from wp_postmeta WHERE `meta_key` = 'yoururl_value' AND `meta_value` LIKE '%bbbb.com%'
复制代码

建立a_temp存放筛选出来的数据

  1. create table a_temp as select * from wp_postmeta WHERE `meta_key` = 'yoururl_value' AND `meta_value` LIKE '%bbbb.com%'
复制代码

将包含cccc.com内容的数据追加插入a_temp

  1. insert into a_temp(meta_id,post_id,meta_key,meta_value) select * from wp_postmeta WHERE `meta_key` = 'yoururl_value' AND `meta_value` LIKE '%cccc.com%'
复制代码
  1. create table a_temp as select * from wp_postmeta WHERE `meta_key` = 'yoururl_value' AND `meta_value` LIKE '%bbbb.com%';
复制代码

以下是删除/左边字符

  1. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
  2. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
  3. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
  4. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
  5. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
  6. update a_temp SET meta_value = SUBSTRING(meta_value, INSTR(meta_value, '/') + 1);
复制代码

替换内容中的部分字符,对内容进行格式化
  1. UPDATE a_temp SET meta_value = REPLACE( meta_value, ' ', '' );
  2. UPDATE a_temp SET meta_value = REPLACE( meta_value, '.', '_' );
  3. UPDATE a_temp SET meta_value = REPLACE( meta_value, '_rar', '.rar' );
  4. UPDATE a_temp SET meta_value = REPLACE( meta_value, ',', '' );
  5. update a_temp SET meta_value= CONCAT('http://xxxx.com/',meta_value);
复制代码

用临时表的内容替换原字段内容
  1. DELETE FROM wp_postmeta WHERE meta_key = 'yoururl_value' AND `meta_value` LIKE '%bbbb.com%'
复制代码

将a_temp表处理好后的下载地址,更新到wp_postmeta的yoururl_value

  1. UPDATE wp_postmeta,a_temp  SET wp_postmeta.meta_value=a_temp.meta_value  WHERE wp_postmeta.meta_id=a_temp.meta_id
复制代码

1. 删除所有未使用的标签
  1. DELETE a,b,c
  2. FROM wp_terms AS a
  3. LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
  4. LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
  5. WHERE c.taxonomy = 'post_tag' AND c.count = 0
复制代码

2.删除所有文章修订版本(Revisions)以及它们的Meta数据
  1. DELETE a,b,c
  2. FROM wp_posts a
  3. LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
  4. LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
  5. WHERE a.post_type = 'revision'
复制代码

3. 更改WordPress地址和首页地址
  1. UPDATE wp_options SET option_value = replace(option_value, 'http://www.旧网址.com', 'http://www.新网址.com') WHERE option_name = 'home' OR option_name = 'siteurl'
复制代码

4. 更改文章的GUID
  1. UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.旧网址.com', 'http://www.新网址.com')
复制代码

5. 更改正文中的链接地址
  1. UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.旧网址.com', 'http://www.新网址.com')
复制代码

6. 更新文章的Meta值
  1. UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.旧网址.com', 'http://www.新网址.com')
复制代码

7. 重设Admin密码
  1. UPDATE wp_users SET user_pass = MD5( 'new_password' ) WHERE user_login = 'admin'
复制代码

8. 重设admin的用户名
  1. UPDATE wp_users SET user_login = 'newname' WHERE user_login = 'admin'
复制代码

9. 将作者a的文章全部转移到作者b
  1. UPDATE wp_posts SET post_author = 'b' WHERE post_author = 'a'
复制代码

10. 删除文章的meta标签
  1. DELETE FROM wp_postmeta WHERE meta_key = 'your-meta-key'
复制代码

11. 导出所有评论中的邮件地址
  1. SELECT DISTINCT comment_author_email FROM wp_comments
复制代码

12. 删除所有的Pingback
  1. DELETE FROM wp_comments WHERE comment_type = 'pingback'
复制代码

13. 删除所有的垃圾评论
  1. DELETE FROM wp_comments WHERE comment_approved = 'spam'
复制代码

14. 禁用所有激活的插件
  1. UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins'
复制代码

15. 罗列所有未使用的Meta标签
  1. SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE  wp.ID IS NULL
复制代码

16. 关闭旧文章的留言
  1. UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2009-01-01' AND post_status = 'publish'
复制代码

17. 更新留言者的网址
  1. UPDATE wp_comments SET comment_author_url = REPLACE( comment_author_url, 'http://旧网址.com', 'http://新网址.com' )
复制代码

18. 更新正文内所有的’target=”_blank”‘为’rel=”nofollow”‘
  1. UPDATE wp_posts SET post_content = REPLACE (post_content, 'target="_blank',  'rel="nofollow')
复制代码

19.删除未使用的Meta标签
  1. DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL
复制代码

20.更改文章自定义字段的名称
  1. UPDATE `wp_postmeta` SET `meta_key` = '新名称' WHERE `meta_key` = '旧名称';
复制代码

21.批量修改文章的发布日期和修改日期:
  1. update wp_posts set post_date = replace(post_date, '2020-11-25', '2020-11-23') WHERE `ID` between 653 AND 652;
  2. update wp_posts set post_date_gmt = replace(post_date_gmt, '2020-11-25', '2020-11-23') WHERE `ID` between 612 AND 652;
  3. update wp_posts set post_modified = replace(post_modified, '2020-11-25', '2020-11-23') WHERE `ID` between 612 AND 652;
  4. update wp_posts set post_modified_gmt = replace(post_modified_gmt, '2020-11-25', '2020-11-23') WHERE `ID` between 612 AND 652;
复制代码

字段含义:
post_date(文章发布日期)
post_date_gmt(文章发布日期,格林威治时间)
post_modified(文章修改时间)
post_modified_gmt(文章修改时间,格林威治时间)

转自:https://xiaohost.com/1647.html
分享至 : QQ空间
收藏

4 个回复

倒序浏览
{author} 感谢楼主分享
回复 使用道具 举报
zz007 列兵 2020-11-28 20:08:20
3#
膜拜大神3秒钟
回复 使用道具 举报
核动力 列兵 2020-11-28 22:10:20
4#
支持,顶一下。
回复 使用道具 举报
非常感谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入网盟
关闭

华夏网盟推荐 上一条 /1 下一条