User Tools

Site Tools


mysql:exportcsv

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
mysql:exportcsv [2011/10/24 12:43] rlunaromysql:exportcsv [2022/12/02 22:02] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== 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.
 +
 +<code sql>
 +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 '"'; 
 +  
 +</code>
 +
 +====== Import from CSV ======
 +
 +
 +<code sql>
 +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,...]
 +
 +</code>
 +
 +http://dev.mysql.com/doc/refman/5.5/en/load-xml.html
 +
 +
 +