User Tools

Site Tools


mysql:exportcsv

Make a select and export to csv

I've tried this to make a csv file, to import directly into Microsoft Excel. You can try also with character set 'utf-8', to export international character set, but this doesn't match very well with Excel.

SELECT blah, blah
  FROM TABLE 
  INTO OUTFILE 'PUT_HERE_YOUR_FILENAME'
  CHARACTER SET 'latin1'  -- latin charset, ideal for importing into excel
  COLUMNS TERMINATED BY ';'
  ENCLOSED BY '"'; 
 

Import from CSV

LOAD XML [LOW_PRIORITY | CONCURRENT] 
LOCAL INFILE 'HERE_GOES_THE_FILENAME'
[REPLACE | IGNORE]
INTO TABLE [db_name.]tbl_name
[CHARACTER SET charset_name]
[ROWS IDENTIFIED BY '<tagname>']
[IGNORE NUMBER [LINES | ROWS]]
[(column_or_user_var,...)]
[SET col_name = expr,...]

http://dev.mysql.com/doc/refman/5.5/en/load-xml.html

mysql/exportcsv.txt · Last modified: 2014/12/24 10:42 (external edit)