Cleaning Up an old WP Database

Come across this old post.

Install the WP-DBManager plugin by Lester Chan

Check last time table was used:

SELECT UPDATE_TIME 
FROM   information_schema.tables WHERE  
TABLE_SCHEMA = 'db_name' AND TABLE_NAME = 'table_name'

Compile a list, on the staging server, first of tables that we don’t seem to still be using:

DROP TABLE IF EXISTS `wp_booking`;
DROP TABLE IF EXISTS `wp_bookingdates`;
DROP TABLE IF EXISTS `wp_clean_up_optimizer`;
DROP TABLE IF EXISTS `wp_cleanup_optimizer_licensing`;
DROP TABLE IF EXISTS `wp_edn_subscriber`;
DROP TABLE IF EXISTS `wp_hc_hmw_short_code`;
DROP TABLE IF EXISTS `wp_woocommerce_payment_tokens`;
% etc...

Thank you SO for one liner to remove woocommerce tables

SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_schema, '`.`', table_name,'`') INTO @tables FROM information_schema.tables 
  WHERE table_schema = 'database_name' AND table_name LIKE BINARY 'wp_woocommerce%';

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt1 FROM @tables;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

Leave a Reply

Your email address will not be published. Required fields are marked *