3

I used the following command to export some fields of MySQL table including a JSON field(attributes) into CSV file:

SELECT name, attributes, product_url FROM products INTO OUTFILE '/var/lib/mysql-files/toys.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

But, I get each key-value pair of attributes(JSON field) in separate columns.

How to get all those key-values(attributes column of MySQL table) in a single column of CSV file?

1 Answer 1

1

I found a solution that was enough to get my job done. I exported those fields into TSV instead of CSV using following slightly modified command:

SELECT name, attributes, product_url FROM products INTO OUTFILE '/var/lib/mysql-files/toys.tsv' FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';

Still, if anyone has an exact solution to the problem, that would be greatly appreciated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.