WordPress 清理数据库冗余数据命令


删除文章修订版本

DELETE FROM wp_posts WHERE post_type = 'revision';
wp 媒体管理器上传图片的时候同事会成才attachment 文章格式,如果你不需要根据这个检索图片的话也可以删掉。

DELETE FROM wp_posts WHERE post_type = 'attachment';
wp_postmeta是重灾区,可以执行以下命令

DELETE FROM wp_postmeta WHERE meta_key = '_edit_lock';
DELETE FROM wp_postmeta WHERE meta_key = '_edit_last';
DELETE FROM wp_postmeta WHERE meta_key = '_revision-control';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT post_id FROM wp_posts);
DELETE FROM wp_postmeta WHERE meta_key = '_wp_old_slug';
DELETE FROM wp_postmeta WHERE meta_key = '_revision-control';
DELETE FROM wp_postmeta WHERE meta_value = '{{unknown}}';

如果你不需要管理你的多媒体文件可以使用下面这两句

DELETE FROM wp_postmeta WHERE meta_key = '_wp_attached_file';
DELETE FROM wp_postmeta WHERE meta_key = '_wp_attachment_metadata';

综合到一起可直接执行下面两句

DELETE FROM wp_postmeta WHERE meta_key in ('_edit_lock', '_edit_last', '_wp_old_slug', '_revision-control', '{{unknown}}', '_wp_attached_file', '_wp_attachment_metadata');
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);

删除所有垃圾评论

DELETE FROM wp_comments WHERE comment_type = 'trash';
删除所有待审评论

DELETE FROM wp_comments WHERE comment_approved = '0';

一般来说直接删掉wp_commentmeta就可以了,我是完全不使用这货的,如果你使用了commentmeta存储信息请谨慎执行此句

TRUNCATE TABLE wp_commentmeta
wp_options

尤其是使用我的网易云音乐和牧风的hermit,都会在wp_options表中产生大量垃圾数据。

DELETE FROM wp_options WHERE option_name LIKE 'transient%';
DELETE FROM wp_options WHERE option_name LIKE 'transient_timeout%'

这样会删除所有临时数据,包括未过期的,谨慎使用。

未经允许不得转载:445IT之家 » WordPress 清理数据库冗余数据命令

赞 (0) 打赏

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏