来源: 互联网 日期: 2020-07-16 17:08:43
由于最适合搭建wordpress的web环境是php+mysql+apache所以在使用wordpreess的过程中必不可少的要接触到一些sql操作,下面介绍一些常用wordpress常用sql查询。
清除Microsoft Word文档中的奇怪字符(有些朋友喜欢用Word文档写文章然后粘贴到wordpress,但是这样有可能会在wordpress数据库中产生一些奇怪的字符。):
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'â€', '”'); UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’'); UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘'); UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–'); UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—'); UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-'); UPDATE wp_posts SET post_content = REPLACE(post_content, '…', '…'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '“', '“'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, 'â€', '”'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '’', '’'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '‘', '‘'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '—', '–'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '–', '—'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '•', '-'); UPDATE wp_comments SET comment_content = REPLACE(comment_content, '…', '…');
使用sql查询更改wordpress用户密码:
UPDATE 'wp_users' SET 'user_pass' = MD5('密码') WHERE 'user_login' ='账户登录名' LIMIT 1;
将某个用户的文章转移到另一个用户:
UPDATE wp_posts SET post_author=新的用户ID WHERE post_author=旧的用户ID;
批量删除垃圾评论:
DELETE from wp_comments WHERE comment_approved = '0';
查找已添加的未使用标签(tag):
SELECT * From wp_terms wt INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id WHERE wtt.taxonomy='post_tag' AND wtt.count=0;
获取所有评论用户的邮箱号列表:
SELECT DISTINCT comment_author_email FROM wp_comments;
批量禁用所有已开启的插件:
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
批量禁止在旧文章中评论:
UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2009-01-01' AND post_status = 'publish'; //关闭某时段之前的文章的评论功能日期格式为:年-月-日
以上SQL查询都是以wp_默认前缀为例,使用时请按自己的数据库前缀来进行操作,进行数据库操作前请备份好数据!
(抓润网帝国模板 www.zhuarun.com)