Sunday, September 25, 2011

Saving MySQL Queries to CSV

Alright, didn't get any posts in last week and need to work on that.  Some of it has to do with a new computer and realizing this fantasy football stat endeavor does take more time than I thought.  Some of it is my lack of expertise in Python, and little time to do that analysis.  One little note for knowledge sake is the command to save a MySQL query to a CSV file, this way I can play with the stats in a spreadsheet. Here is the code:

mysql> SELECT * INTO OUTFILE '/tmp/pbp2010.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM pbp2010 WHERE 1;

Be sure you have permission to write into "tmp".  The table in this is example is "pbp2010".

No comments: