Search code examples
mysqlsqlcsvweka

Export a SQL database into a CSV file and use it with WEKA


How can I export a query result from a .sql database into a .csv file? I tried with

SELECT * 
FROM players 
  INTO OUTFILE 'players.csv' 
  FIELDS TERMINATED BY ',' 
  LINES TERMINATED BY ';';` 

and my .csv file is something like:

p1,1,2,3
p2,1,4,5

But they are not in saparated columns, all are in 1 column.

I tried to create a .csv file by myself just to try WEKA, something like:

p1  1  2  3
p2  1  4  5

But WEKA recognizes p1 1 2 3 as a single attribute.

So: how can I export correctly a table from a sql db to a csv file? And how can I use it with WEKA?

EDIT

Is it possible to add a header line with columns names? I have read something online but I am not able.



I'm using MySQL 5.5.


Solution

  • You need to inform weka about format of your csv file. You can do so while opening csv file and invoking options dialog, see below images. Also you need to terminate your lines with "\n" instead of ";".

    enter image description here enter image description here