Knowledge for the World

How to export mysql query as csv

1

For instance, if you're trying to get all of the users from the 'users' table: SELECT * FROM users

2

Append this onto the end of the query to output the results to a file /tmp/users.csv INTO OUTFILE '/tmp/users.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'

3

SELECT * FROM users INTO OUTFILE '/tmp/user.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'