We would like to remove all product images from the database and the file-system in Magento 2.2.8 shop.

There is a solution for Magento 1

Magento Delete all Product Images

Can this easily be adapted to Magento 2?

I am thinking about

  • rm -r pub/media/catalog/product/? pub/media/catalog/product/cache # keeping placeholder folder
  • And deleting from some tables in the database (which one) ?
  • Reindex

is this safe or are complications to expect?

We rather would not like to iterate over each product and save it, because of performance reasons.


Apart from:




tables, now Magento 2 has one more table


which keeps track of removal of product in catalog_product_entity table, and relates this table to catalog_product_entity_media_gallery.

You need to check this table also.

One more table (catalog_product_entity_media_gallery_value_video) has been introduced in Magento 2, which keeps entries related to product videos.

Please review this table if you have any videos for products.

After the database operation, you can remove the image files from:

  • pub/media/catalog/product/ folder
  • pub/media/catalog/product/cache # keeping placeholder folder

That's all.

Note: Keep a backup of the database before doing any exercise on the database.


Based on mohit's answer:

truncate catalog_product_entity_media_gallery_value;
truncate catalog_product_entity_media_gallery_value_to_entity;
delete from catalog_product_entity_media_gallery;  # 9 sec
delete from catalog_product_entity_varchar where attribute_id in ( select 
     attribute_id from eav_attribute where attribute_code like "%image" and 
     entity_type_id = 4 ); # 23 sec in our case (20000 Products)
  • Alex missed the removing query for thumbnail attribute. – sergei.sss May 19 at 18:44
  • What do you mean? Feel free to post another answer :) – Alex May 20 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.