Today we just want to share a little script we use on a regular basis that we thought may come in handy for a few of you out there. This simply clears all product data from your Magento installation – very handy if you import your data on a regular basis and it needs refreshing or if you need to delete old demo data.

First connect to MySQL using the following in SSH:

mysql -u YOUR-USERNAME -p

Next you’ll be prompted for your password, just type it in and hit enter.

You’re all set! Navigate back to your Magento and give it a quick double check, you should find that all products have now gone.

If you need to do this on a regular basis then a cron job may be more fitting, just bung the above code in a .sql file and use a cron job similar to the below:

00 22 * * * PATH/TO/MYSQL MAGENTO-DATABASE-NAME < clear-products.sql

Simply swap in your MySQL path and Magento database name, upload the .sql file you created earlier to your root directory and you are good to go. This cron runs daily at 10PM so change that according to your own needs. For example mine would be the below which runs at 10PM every Friday: