Customer Grid Empty

The customers area of Magento 2 may be empty, despite the fact you can see many rows/customers in customer_entity and so on. This grid depends on an indexer called the customer_grid index.  And stores data in customer_grid_flat.  Odds are the flat table is empty, which is populated by the indexer.

Trace the indexer to see if it works, you may see it hang on a query like this –

sendto(5, ",\7\0\0\3SELECT `e`.*, `e`.`entity_id`, TRIM(CONCAT_WS(' ', IF(`e`.`prefix` <> '', `e`.`prefix`, NULL), IF(`e`.`firstname` <> '', `e`.`firstname`, NULL), IF(`e`.`middlename` <> '', `e`.`middlename`,<br />
NULL), IF(`e`.`lastname` <> '', `e`.`lastname`, NULL), IF(`e`.`suffix` <> '', `e`.`suffix`, NULL))) AS `name`, `e`.`email`, `e`.`group_id`, `e`.`created_at`, `e`.`website_id`, `e`.`confirmation`,<br />
 `e`.`created_in`, `e`.`dob`, `e`.`gender`, `e`.`taxvat`, (SELECT `lookup`.`last_visit_at` FROM `customer_visitor` AS `lookup` WHERE (`lookup`.`customer_id` = `e`.`entity_id`) ORDER BY `lookup`.`last_visit_at`<br />
DESC LIMIT 1) AS `last_visit_at`, TRIM(CONCAT_WS(' ', IF(`shipping`.`street` <> '', `shipping`.`street`, NULL), IF(`shipping`.`city` <> '', `shipping`.`city`, NULL), IF(`shipping`.`region` <> '',<br />
`shipping`.`region`, NULL), IF(`shipping`.`postcode` <> '', `shipping`.`postcode`, NULL))) AS `shipping_full`, TRIM(CONCAT_WS(' ', IF(`billing`.`street` <> '', `billing`.`street`, NULL), IF(`billing`.`cit"...,<br />
 1840, MSG_DONTWAIT, NULL, 0) = 1840

Ok, that is inconvenient. The problem is the customer_visitor table. If it has several hundred thousand rows, empty it → delete from customer_visitor

Then try reindexing again, you may have to update the status in indexer_state to be invalid

update indexer_state set status=”invalid” where state_id=1;

Then the grid should populate.  This is very similar to Magento 1 where the log_url* tables would get very large and cause dramatic slowdowns in the backend.