Friday, February 29, 2008

Import a CSV file into MySql

I recently received a CSV file that I needed to import into MySQL, I tried to use Navicat on a Windows machine but the file was large enough to cause it to hang. So I went to the command line on the server and created it as follows

mysqlimport --fields-terminated-by="," --fields-optionally-enclosed-by="\"" --lines-terminated-by="\n" databasename /pathtocsvfile/csv.csv -u mysqlusername -p

note that the name of the file I was importing was csv.csv, in order for this to work you must have created a table that will accept this data wit the same name as the file you are importing (minus the extension)

No comments: