How to clean Magento 1.x database

When I try to make a copy of the Magento 1 site, it takes forever to restore the MySQL database. The size of the database was 8.6 GB. On checking, I found some tables like report_event are very large.

To clear the tables, Magento provides a script, you can run it with

php -f shell/log.php clean --days 2

This will delete all logs that are 2 days old from the MySQL database. If you need to keep logs for 60 days, you can use the following command

php -f shell/log.php clean --days 60

clean magento 1 mysql database

After running the log cleaner script, the size of the database changed from 8.6 GB to 829 MB.

magento database size before and after cleaning

Cleaning Manually

If you need to clean MySQL database manually using phpMyAdmin or MySQL command prompt, you can run the following SQL commands

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
SET FOREIGN_KEY_CHECKS=1;

Using Magento Backend

You can log in to the Magento Admin area, then go to

System > Configuration > Advanced > System > Log Cleaning

You have the option to auto clean the Magento store logs.

Comments

Leave a Reply

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