Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    6

    Unanswered: 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.

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    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.

  3. #3
    Join Date
    Jan 2004
    Posts
    6
    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •