简体   繁体   中英

Need a script File to clear Cache Tables in a Drupal Database

I need to take a dump of MySQL Database, i usaully do these manual steps do Perform dumping.

login to phpmyadmin
select database
select sql tab
paste these lines

TRUNCATE watchdog ;
TRUNCATE cache ; and
TRUNCATE cache_admin_menu ;

And click on OK to clean the cache.

I need to carryout the same activity via sime automated way, so that i can run in Cron job

[root@localhost home]# mysql -u root -ppasswd < /root/Downloads/testscript.sql

I had create one file with name testscript.sql

text in the file as follows

/*
* My First MySQL Script - testscript.sql.
* You need to run this script with an authorized user.
*/
USE dbname; -- Set system database 'dbname' as the current database
TRUNCATE `cache`;
TRUNCATE `cache_admin_menu`;
TRUNCATE `cache_block`;
TRUNCATE `cache_bootstrap`;
TRUNCATE `cache_field`;
TRUNCATE `cache_filter`;
TRUNCATE `cache_form`;
TRUNCATE `cache_image`;
TRUNCATE `cache_libraries`;
TRUNCATE `cache_menu`;
TRUNCATE `cache_page`;
TRUNCATE `cache_path`;
TRUNCATE `cache_rules`;
TRUNCATE `cache_token`;
TRUNCATE `cache_update`;
TRUNCATE `cache_views`;
TRUNCATE `watchdog`;

you can run the following command

mysql -u {username} -p{password} -e "FLUSH QUERY CACHE"

or you can create the query, save it on a file and run:

mysql -u {username} -p {password} < /path/to/query.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM