wordpress

SQL语言 wordpress wp_postmeta 表太大 清除优化

wp_postmeata 表

Cleaning wp_postmeta table
参考 https://www.smarthomebeginner.com/clean-wp-commentmeta-wp-postmeta/

SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;

清除前可以删除 删除posts的 revisions

DELETE FROM wp_posts WHERE post_type = "revision"; 

wp_commentmeta 表

SELECT * FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
DELETE FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
SELECT * FROM wp_commentmeta WHERE meta_key LIKE '%akismet%'; 
DELETE FROM wp_commentmeta WHERE meta_key LIKE '%akismet%';

wp_options 表相关

DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%')