Importing a CSV file into a MySQL Table
Posted by:
paul chan
Date: January 03, 2009 06:22AM
Hello, I've been reading and figuring how to do this alas I need some help.
I'm trying to import a CSV file with stock price data into MYSQL table, the data from my CSV looks like this:
12/29/2008,2.8,2.92,2.78
12/22/2008,2.93,2.99,2.65
12/15/2008,2.8,3.05,2.7
Where the fields would correspond to
date, high, low, close
In the table I created I have 5 fields,
id, date, high, low, close
My questions are:
Since my csv file doesn't have an id column, would I need to add a new column for id? I have set id to autonum so it should fill itself automatically as I import data no?
Second, I've read abt the format of date in MYSQL to be yyyy-mm-dd format so I'm importing my dates as varchar for simplcity sake, or is this wrong?
I've been trying to import these data using phpmyadmin/command line client without any result, can anyone out there please enlighten me?
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| date | varchar(11) | NO | | NULL | |
| high | double | NO | | NULL | |
| low | double | NO | | NULL | |
| close | double | NO | | NULL | |
+--------+-------------+------+-----+---------+----------------+