Thanks to everyone who helped me with my question below. Here is the
solution I found:
1. I found a website that has a CSV-to-SQL utility. Halfway down the
page you'll see a form where you can upload a CSV file and it will
display corresponding SQL statements, both to create the table and to
populate it with the data.
2. Since my files were too large for the web form, I used "head -n 100
largefile.csv > smallfile.csv" to create smaller files with enough data
that the column types would be generated correctly.
3. I then executed just the CREATE TABLE statements and populated the
tables with LOAD DATA INFILE:
LOAD DATA LOCAL INFILE 'largefile.csv' INTO TABLE `abc` FIELDS
TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';
Thanks to the owner of the website (Antje Binas-Holz) for the free
Begin forwarded message:
> From: Richard Miller <richardkmiller@stripped>
> Date: April 5, 2005 6:17:34 PM MDT
> To: Mysql <mysql@stripped>
> Subject: CSV-to-SQL?
> I have a dozen, very large CSV files that I would like to put into a
> MySQL database, with 1 table per file. Does anyone know of a PHP (or
> other) script that can read the first few lines of a CSV file and
> create an appropriate CREATE TABLE statement based on the data it
> finds? (Even better, it could import the file afterwards!) I'm not
> picky about data types here; I'd simply like to get this data into
> tables so I can work with it more easily.
> Richard Miller
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
|• CSV-to-SQL?||Richard Miller||10 Apr|