WordPress清理 wp_postmeta 数据表攻略

发布于 2018-09-27  920 次阅读


wp_postmeta 数据表是 WordPress 中存储文章附带信息的,除了一些特定的情况下,里面的数据是没有用的,下面在给出几条语句让你的 wp_postmeta 表变得干净。

操作之前请先备份数据库。然后执行下面的SQL语句清理和优化 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);

通过上面对 wp_postmeta 数据表的优化和清理,我们的数据库瘦身不少,执行效率也有所提升。


Never give up your dreams.