How to import a csv file into mysql from the prompt

For the follows out there who do not know how to import coma separated data into mysql from the prompt, here it is:


PATH is the path to the csv file (can be relative to the directory you were in before logging into mysql)
TABLE is the table name that you have already created and whos fields match the csv file fields.
USERNAME is the mysql user that have access to insert data into TABLE
DATABASE is the database containing that table

- login to mysql by typing: mysql -u USERNAME -p DATABASE
The prompt will ask you for the user password, type it.

- Execute the following query:

load data local infile ‘PATH’ into table TABLE fields terminated by ‘,’ lines terminated by ‘\n’;

And voila.

8 Responses to “How to import a csv file into mysql from the prompt”

  1. Top advertising agencies in Pakistan says:

    Thanks for posting!

  2. Marketing Agency says:

    I have recently been searching for information about this topic for ages and yours is the best I have discovered so far.

  3. Advertising agencies in Lahore says:

    Well, very good post with informative information.

  4. Advertising as profession in Estonia says:

    Wonderful site and I wanted to post a note to let you know,

  5. Advertising says:

    Thanks a lot for your guidance and sharing information.

  6. bilgi deresi says:

    Yaz? için te?ekkür ederim.

  7. Johnny says:

    pruthvi, where is the filename.csv located? for instance, if it’s in c:\somefolder\filename.csv, then you need to escape the backslash, and hence use:

    load data local infile ‘c:\\somefolder\\filename.csv’ into table …..

  8. pruthvi says:

    the program displays an error “File not found. Make sure you specified the correct path.”
    how should i write the file name like filename.csv is ok….

Leave a Reply