提示:清理前请先备份数据库,出问题重新导入数据,安全第一。
SQL语句如下:
DELETE FROM `wp_posts` WHERE `wp_posts`.`post_content` = '';
DELETE FROM `wp_posts` WHERE `wp_posts`.`post_title` = '';
DELETE FROM `wp_posts` WHERE `post_type` = 'revision';
DELETE FROM `wp_postmeta` WHERE `meta_key` = '_edit_lock';
DELETE FROM `wp_postmeta` WHERE `meta_key` = '_edit_last';
另外两条语句,句清理和优化 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 = '_wp_old_slug';
DELETE FROM wp_postmeta WHERE meta_key = '_revision-control';
DELETE FROM wp_postmeta WHERE meta_value = '{{unknown}}';
执行完毕能够删除掉95%以上的数据,算的上是极限优化了。通过上面对 wp_postmeta 数据表的优化和清理,我们的数据库瘦身不少,执行效率也有所提升。