How to get customer and company data in a CSV file from MySQL?
-
14-04-2021 - |
Question
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?
Solution
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;
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 127.0.0.1 -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 127.0.0.1 -u magento -pmagento magento < customer-company-ua.sql | sed 's/\t/,/g' > customer-company.csv
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange