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_%';


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

OPTIMIZE TABLE wp_commentmeta; 
OPTIMIZE TABLE wp_comments; 
OPTIMIZE TABLE wp_links;
OPTIMIZE TABLE wp_options;
OPTIMIZE TABLE wp_postmeta;
OPTIMIZE TABLE wp_posts;
OPTIMIZE TABLE wp_terms;
OPTIMIZE TABLE wp_term_relationships;
OPTIMIZE TABLE wp_term_taxonomy;
OPTIMIZE TABLE wp_usermeta;
OPTIMIZE TABLE wp_users;
初次使用的话,建议先备份一下数据库。

关键词: wordpress , sql语句 , mysql

上一篇: win7 c盘扩容方法:Partition Wizard Home Edition 8.0分区扩容使用教程
下一篇: 利用hh.exe反编译CHM电子书为HTML格式 BAT版

目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):