alexgorbatchev

Friday, August 30, 2013

Using MySQL LOAD DATA INFILE on Windows

Many times I need to load data into the MySQL database backing my Grails application before my initial release.  And frequently those databases include tables with last_updated and date_created timestamp fields.  Instead of entering the values into a csv file, I found it is very easy to set them programmatically while loading other data from a file like the following:

LOAD DATA INFILE 'D:\\sql_data\\available_samples.csv' 
INTO TABLE sample
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
  (id, version, barcode, used)
 SET last_updated = NOW(), date_created = NOW();

References

No comments:

Post a Comment