drop wpstatistics tables.md - plembo/onemoretech GitHub Wiki
Drop WP Statistics Tables
August 3, 2016
Had to remove the WP Statistics plugin from WordPress for various reasons. Problem was, it didn't offer to clean up the tables it had created on uninstall (the latest version claims it can/will do this).
So I had to drop the tables manually. On a 60 blog multisite (7 tables per site).
Here's a MySQL script to get the job done:
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.`', table_name, '`') INTO @tables FROM
(select * from
information_schema.tables
WHERE table_schema = 'oursites' AND table_name LIKE 'wp_%_statistics_%'
LIMIT 10) TT;
SET @tables = CONCAT('DROP TABLE ', @tables);
select @tables;
PREPARE stmt1 FROM @tables;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
NOTE: Slight modification to table name definition for the main site tables, which would be 'wp_statistics_%'.
To finish the job I had to run the script several times due to the script's having to accomodate the 1024 character limit for GROUP_CONCAT.
Full credit (and thanks) to Ron Klien for posting the answer on Stackoverflow.
Copyright 2004-2019 Phil Lembo