Generate Statements to Truncate Drupal Cache Tables

Last modified: 
Thursday, February 18th, 2016
Topics: 
MySQLDrupal

This query will generate the sql statements to truncate all drupal cache tables.

SELECT DISTINCT CONCAT(  
    "TRUNCATE TABLE ", 
    TABLE_SCHEMA,  
    ".",
    TABLE_NAME, 
    ";" ) 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE  "cache_%"
AND TABLE_SCHEMA = 'mydrupaldb';

Outputs something like this:

TRUNCATE TABLE mydrupaldb.cache_admin_menu;
TRUNCATE TABLE mydrupaldb.cache_block;
TRUNCATE TABLE mydrupaldb.cache_bootstrap;
TRUNCATE TABLE mydrupaldb.cache_features;
TRUNCATE TABLE mydrupaldb.cache_field;
TRUNCATE TABLE mydrupaldb.cache_file_styles;
TRUNCATE TABLE mydrupaldb.cache_filter;
TRUNCATE TABLE mydrupaldb.cache_form;
TRUNCATE TABLE mydrupaldb.cache_image;
TRUNCATE TABLE mydrupaldb.cache_media_xml;
TRUNCATE TABLE mydrupaldb.cache_menu;
TRUNCATE TABLE mydrupaldb.cache_page;
TRUNCATE TABLE mydrupaldb.cache_path;
TRUNCATE TABLE mydrupaldb.cache_styles;
TRUNCATE TABLE mydrupaldb.cache_token;
TRUNCATE TABLE mydrupaldb.cache_update;
TRUNCATE TABLE mydrupaldb.cache_views;
TRUNCATE TABLE mydrupaldb.cache_views_data;

References

How Can I truncate Multiple Tables in MySql?


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.