sql语句

wordpress数据库优化之执行sql语句减少mysql数据量

清理数据库的残留无效数据,可以用以下的语句(语句来源于WP Clean Up插件源代码):


DELETE FROM wp_posts WHERE post_type = 'revision';
DELETE FROM wp_posts WHERE post_status = 'draft';
DELETE FROM wp_posts WHERE post_status = 'auto-draft';
DELETE FROM wp_comments WHERE comment_approved = '0';
DELETE FROM wp_comments WHERE comment_approved = 'spam';
DELETE FROM wp_comments WHERE comment_approved = 'trash';
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM wp_comments);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_options WHERE option_name LIKE '_site_transient_browser_%' OR 
option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR
 option_name LIKE '_transient_timeout_feed_%';

优化数据表,可以用以下的语句:

» 阅读全文

关键词: wordpress , sql语句 , mysql

Mysql实现文章查询上一篇和下一篇功能,附sql语句?

mysql实现文章查询上一篇和下一篇功能,附sql语句?

最近在做一个项目用到的文章查询上一篇和下一篇功能,详见:http://www.yifen5.com

Mysql实现文章查询上一篇和下一篇功能,sql语句:

(select * from articles where id < #id# order by id desc limit 1)
union all 
(select * from articles where id > #id# order by id limit 1)

OK,网上大部分都是这么干的,效率上的话,包子强烈建议不要 select * 之类的,效率与指定的几个字段效率有点区别。

关键词: sql语句 , mysql