If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > newbie data import question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-06-04, 09:30
lothario lothario is offline
Registered User
 
Join Date: Jan 2004
Posts: 6
newbie data import question

I am new to MySQL but I some basic database experience.
I have about 50,000 rows of data in a CSV file.

Where I can find some examples of SQL scripts that show how to:
a. Create a database X.
b. Create a table Y.
c. Import the 50,000 rows of CSV data into table Y.
Reply With Quote
  #2 (permalink)  
Old 05-06-04, 14:19
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
just create your database itself by naming it from the mysql prompt
Code:
mysql> create database mynewdatabase;

mysql> create table newtable (
id int,
firstname varchar(15),
lastname varchar(15)
);

mysql> LOAD DATA INFILE 'fullpathtofile.csv' into table newtable fields 
delimited by ',' optionally enclosed by '"';
some things to note:

at the end that is a double quote enclosed by two single quotes. Most .csv files put double quotes around text. The delimited by is also standard since most files will have fields separated by commas.

make sure the fullpathtofile is correct either under linux or windows style (i.e. the slashes for filepaths are / or \ depending on what OS you are using). In Linux you must also make the file readable by your database, actually world readable doesn't hurt.

the mysql> does not need to be typed in. It is just there to show you that there are different points when you begin a new command.
Reply With Quote
  #3 (permalink)  
Old 05-08-04, 04:31
lothario lothario is offline
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks for the help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On