Novice
Novice

Reputation: 1161

LOADING LOCAL .CSV file into MYSQL Table

I have a local file named UpdateTable.csv that looks like this:

Chromosome  ProbeCount  TranscriptCount

   chr1       84453         2887
   chr10      32012         1087
   chr11      49780         1721
   chr12      39723         1402

...etc

I just created a table, named "SUMMARY" that has the same row titles. I need to import the file into my table from my desktop..

Thank you for your help!

Upvotes: 0

Views: 206

Answers (2)

Oleg Liski
Oleg Liski

Reputation: 583

You can use Load data infile

Read more here: http://dev.mysql.com/doc/refman/5.6/en/load-data.html

In your situation, something like:

LOAD DATA INFILE 'c:/users/USER_NAME/Desktop/file.csv'
    INTO TABLE summary
    FIELDS terminated by "\t"
    LINES terminated by "\r\n"

Of course, this SQL is only an example. Please read the manual.

Upvotes: 1

Florin Stingaciu
Florin Stingaciu

Reputation: 8275

mysqlimport [options] db_name textfile1 [textfile2 ...]

For each text file named on the command line, mysqlimport strips any extension from the file name and uses the result to determine the name of the table into which to import the file's contents. For example, files named patient.txt, patient.text, and patient all would be imported into a table named patient.

So in your case, you would have to change your file name from UpdateTable.csv to SUMMARY.csv and remove the first two lines of that file. It would something like

mysqlimport --fields-escaped-by=, db_name SUMMARY.csv

**EDIT acutally one a second look, your file is not a csv (Comma Separated ...). Your file is tab separated and thus the argument for fields escaped by should be '\t'

Upvotes: 0

Related Questions