How to delete all product images in Magento 2?

First we need to understand how images are stored in the database and what are the tables involved that stores the image name, entity_id, attribute_id and attribute_code.

catalog_product_entity_varchar is used for storing product images value.

eav_attribute table

catalog_product_entity_media_gallery_value_to_entity that joins catalog_product_entity_media_gallery and catalog_product_entity tables.


Step 1 : Delete all the product image attribute code values. Where 87, 88 and 89 are the attribute_id for attribute_code image, small_image and thumbnail respectively.

Step 2 : All the catalog product gallery images are stored in these three tables. They need to be removed from the database. Use your favourite database management application.

Step 3 : Log in to the Magento server as, or switch to, a user with permissions to write to the Magento file system.

Type y and press Enter.