Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Unanswered: Uploading CSV file to Mysql workbench

    Hi everyone,

    I am new here and new to sql.

    I am running as local host on my machine and am using the Mysql workbench GUI.

    I am trying to write a simple import script for a .csv file that I made for a one table DB call "song". The code looks as follows:

    /* Import from C:\Testsong.csv*/

    LOAD DATA INFILE 'C:\Testsong.csv'
    INTO TABLE test.song
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\n'
    (Artist, Song_Name, Genre, Length_of_Track, Year_Track_Released)

    The Testsong file is located in
    'C:\ProgramData\MySQL\MySQL Server 5.5\Data\Testsong.csv' but the script is still able to read the file based on the path 'C:\Testsong.csv', why is that?

    Also, How can I alter the script so that the first row of the .csv file is not read into the database?

  2. #2
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    Change the script to point to where the file actually is . . . You have told the process to use the file in the C:\ directory . . .

    Possibly i have misunderstood?

    See if the import allows skipping "header(s)" or the first "n" records. I am not familiar with MySql import.

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Be careful using \ in Windows you need to provide \\ or alternatively you can use a single forward slash / instead of the backslash. This may have something to do with why the file was picked up C:filename.txt will use the default folder on the server and the filename.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

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