Customer Database Structure

The Customer module manages all customer-related data in Magento 2, including customer accounts, addresses, and customer groups. Like the Catalog module, it uses the EAV (Entity-Attribute-Value) pattern for flexible attribute management.

Key Relationships

Customer Tables Relationships

Note: This is a simplified diagram showing the main relationships.

Core Customer Tables

customer_entity

The main customer entity table. Each row represents a registered customer account.

ColumnTypeDescription
entity_idintPrimary key
website_idsmallintWebsite ID where customer registered
emailvarcharCustomer email address
group_idsmallintCustomer group ID
store_idsmallintStore view ID where customer registered
created_attimestampWhen the customer account was created
updated_attimestampWhen the customer account was last updated
is_activesmallintWhether the customer account is active

customer_entity_* (EAV Value Tables)

These tables store the actual attribute values for customers. There are separate tables for different data types.

TableData TypeExample Attributes
customer_entity_varcharString valuesfirstname, lastname, middlename
customer_entity_intInteger valuesgender, is_subscribed
customer_entity_decimalDecimal valuesreward_points, store_credit
customer_entity_textLong text valuescustom notes, preferences
customer_entity_datetimeDate/time valuesdob (date of birth)

Customer Address Tables

customer_address_entity

Stores customer addresses. Each customer can have multiple addresses.

ColumnTypeDescription
entity_idintPrimary key
parent_idintForeign key to customer_entity.entity_id
created_attimestampWhen the address was created
updated_attimestampWhen the address was last updated
is_activesmallintWhether the address is active

customer_address_entity_* (EAV Value Tables)

Similar to customer attributes, address attributes are also stored in EAV tables.

  • customer_address_entity_varchar - For street, city, firstname, lastname, etc.
  • customer_address_entity_int - For is_default_billing, is_default_shipping, etc.
  • customer_address_entity_text - For long text values

Customer Group Tables

customer_group

Defines customer groups, which can be used for pricing, discounts, and permissions.

ColumnTypeDescription
customer_group_idintPrimary key
customer_group_codevarcharGroup name
tax_class_idintTax class associated with this group

Customer Authentication Tables

customer_password_reset_link

Stores password reset tokens for customers.

ColumnTypeDescription
customer_idintForeign key to customer_entity.entity_id
tokenvarcharReset token
created_attimestampWhen the token was created

customer_log

Logs customer login activity.

ColumnTypeDescription
customer_idintForeign key to customer_entity.entity_id
last_login_attimestampLast successful login time
last_logout_attimestampLast logout time

Customer Segment Tables

customer_segment

Defines customer segments for targeted marketing (Enterprise Edition only).

ColumnTypeDescription
segment_idintPrimary key
namevarcharSegment name
descriptiontextSegment description
is_activesmallintWhether the segment is active
created_attimestampWhen the segment was created
updated_attimestampWhen the segment was last updated

customer_segment_customer

Maps customers to segments (many-to-many relationship).

ColumnTypeDescription
segment_idintForeign key to customer_segment.segment_id
customer_idintForeign key to customer_entity.entity_id
added_datetimestampWhen the customer was added to the segment
updated_datetimestampWhen the customer's segment membership was updated

Data Analysis Tips

  • For basic customer information, use EAV joins on value tables.
  • For customer address analysis, join customer_address_entity with its EAV tables.
  • For customer activity, use customer_log and sales_order tables.
  • To find attribute IDs, query eav_attribute for the customer entity type.