Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, im quite a newbie when it comes to MySQL but i heard that its possible to import data from a CSV into a mysql table. Can anyone enlighten me ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    61

    How to import CSV into MySQL??


    Hi, im quite a newbie when it comes to MySQL but i heard that its possible to import data from a CSV into a mysql table.

    Can anyone enlighten me on how to do it please? Im running CentOS and usiong MySQL Workbench to connect and run queries.

    I have my CSV formatted so that the first row has the names of my columns on the table that I want to import it to and the following rows are the data that needs importing.

    Cheers,

    Chris,

  2. #2
    Just Joined!
    Join Date
    Mar 2010
    Location
    India
    Posts
    2
    Quote Originally Posted by GreenSkyChris View Post
    Hi, im quite a newbie when it comes to MySQL but i heard that its possible to import data from a CSV into a mysql table.

    Can anyone enlighten me on how to do it please? Im running CentOS and usiong MySQL Workbench to connect and run queries.

    I have my CSV formatted so that the first row has the names of my columns on the table that I want to import it to and the following rows are the data that needs importing.

    Cheers,

    Chris,
    Hey try this out ..
    LOAD DATA LOCAL INFILE 'uniq.csv' into table tblUniq
    fields terminated by ','
    enclosed by '"'
    lines terminated by '\n'
    (uniqName, uniqCity, uniqComments)
    Note:Place the 'data.csv' file into the mysql databases directory before executing the command.

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    61
    Quote Originally Posted by crazyswap View Post
    Hey try this out ..
    LOAD DATA LOCAL INFILE 'uniq.csv' into table tblUniq
    fields terminated by ','
    enclosed by '"'
    lines terminated by '\n'
    (uniqName, uniqCity, uniqComments)
    Note:Place the 'data.csv' file into the mysql databases directory before executing the command.
    Could you tell me where my Mysql databases directory is? Im running CentOS.

    Thanks.

  4. #4
    Just Joined! jippie's Avatar
    Join Date
    May 2006
    Location
    Eindhoven, the Netherlands
    Posts
    76
    Never touch the database files themselves! You'll corrupt the database.

    Enter the database with the following command:

    mysql -u database_username -p name_of_database

    You'll be prompted for the database password, then you can type crazyswap's commands from the mysql> prompt

    Quote Originally Posted by GreenSkyChris View Post
    Could you tell me where my Mysql databases directory is? Im running CentOS.

    Thanks.

  5. #5
    Just Joined!
    Join Date
    Mar 2010
    Location
    India
    Posts
    2
    /var/lib/mysql/

  6. #6
    Just Joined!
    Join Date
    Nov 2010
    Posts
    61
    Quote Originally Posted by crazyswap View Post
    /var/lib/mysql/
    Thank you!

Posting Permissions

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