复制网站的时候,发现数据已经百万级别了
果断删除一些垃圾数据:
执行代码如下:
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}}';
DELETE FROM wp_options WHERE option_name LIKE ('%_transient_%');
DELETE FROM wp_options WHERE option_name REGEXP '_transient_';
TRUNCATE `wp_woocommerce_order_itemmeta`;
TRUNCATE `wp_statistics_visitor_relationships`;
TRUNCATE `wp_comments`;
TRUNCATE `wp_statistics_pages`;
TRUNCATE `wp_actionscheduler_logs`;
TRUNCATE `wp_woocommerce_order_items`;
TRUNCATE `wp_statistics_visitor`;
TRUNCATE `wp_wc_order_product_lookup`;
TRUNCATE `wp_wc_order_stats`;
TRUNCATE `wp_easywpsmtp_debug_events`;
DELETE FROM wp_users WHERE `wp_users`.`ID` != 1;
DELETE FROM wp_comments WHERE comment_approved != '1';
DELETE FROM wp_comments WHERE comment_approved = '0';
DELETE FROM wp_comments WHERE comment_approved = 'spam';
DELETE FROM wp_comments WHERE comment_approved = 'trash';
TRUNCATE `wp_commentmeta`;
DELETE FROM `wp_wc_customer_lookup` WHERE `wp_wc_customer_lookup`.`customer_id` != 1;
DELETE a,b,c FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision';
DELETE FROM wp_posts where (post_status='auto-draft' or post_status='inherit') and post_type='post';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT post_id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM wp_posts);
DELETE a,b,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE (
c.taxonomy = 'post_tag' AND
c.count = 0
);
战绩斐然啊,如图:
数据库瘦了一大圈,我测试下,如有异常,继续编辑帖子。无异常,就以这个为最终结果