How product images are saved in database Magento 2?

A Product is the main entity for any e-Commerce system, A product has multiple information like Title, SKU, Inventory, Images and so more.

Let’s Start with the Main point, A product has multiple images available and we want to know how each product are stored in the database.

catalog_product_entity_varchar used for store product images value.

— Product has one image for all the Role like base, thumbnail, and small_image.

All the value of the image is stored under the catalog_product_entity_varchar table with attribute_id and value field separately.
If product image value is abc.jpg then a value is stored as,

base thumbnail small image magento 2

In the above image,
87 is attribute_id for a base,
88 is attribute_id for thumbnail and
89 is for small_image attribute_id and product id is 2.

You can check each Role attribute id under the eav_attribute table.

All the images value for a product are also store under below tables,

Once you add any images for a product, one entry is generated under a catalog_product_entity_media_gallery table. if you have added multiple images for a product, multiple entries are generated.

— For catalog_product_entity_media_gallery table stored the value of the images as attribute_id with image value.  when you check the above table, you can see attribute_id value as 90 (90 is attribute_id of a gallery) and value field is /a/b/abc.jpg

catalog_product_entity_media_gallery_value table used for product id link with product label value.

catalog_product_entity_media_gallery_value_to_entity used for mapping product entity id with catalog_product_entity_media_gallery_value table.


All the images are stored under pub/media/catalog/product folder in Magento root. If product image name is abc.jpg then its stored under an above folder with an a/b/abc.jpg  path with first folder name is the first character of image and second folder is the second character of the image name.

— If an image has only one character like a.jpg then its stored under a/_/a.jpg path under pub/media/catalog/product

A final path for image name abc.jpg is, pub/media/catalog/product/a/b/abc.jpg