I'm running a Magento Commerce Cloud B2B, and I need to get a list of these data below.

  • Customer ID
  • Customer Name
  • Company Name
  • Company User Agreement

As I can't export a file with these pieces of information above via the admin panel, how could I do it via a MySQL query?

1 Answer 1


You can use MySQL INNER JOIN to do it. This script is going to help you with it:

SELECT customer_grid_flat.entity_id ,customer_grid_flat.name, customer_grid_flat.billing_company, company_erp.`is_end_user_agreement` FROM customer_grid_flat 
INNER JOIN company ON company.company_name = customer_grid_flat.billing_company
INNER JOIN company_erp ON company_erp.company_id = company.entity_id;

Magento 2 get customer data via MySQL query

Export SQL

To export this into a file you can run this code snippet below with the SQL file containing the script above:

mysql -h -u magento -pmagento magento < customer-company-ua.sql > customer-company.csv

Convert it to CSV

To convert it to CSV separated by comma, you can run this command below instead.

mysql -h -u magento -pmagento magento < customer-company-ua.sql | sed 's/\t/,/g' > customer-company.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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