Friday, February 27, 2015

How to export specific columns in a table to a csv file in mysql

Go to the mysql prompt as usual and run the command:
select id, email from users INTO OUTFILE '/Users/zepho/temp/users.csv' FIELDS TERMINATED BY ',';

This will create a csv file with only id, email columns in the users table in the users.csv file.

ERROR 1 (HY000): Can't create/write to file '/var/empty/projects/gold' (Errcode: 2)
ERROR 1 (HY000): Can't create/write to file '/Users/zepho/temp/users.csv' (Errcode: 13)

If you get these errors run:

chmod 777  /Users/zepho/temp