How to upload csv file on mysql table

Discussion in 'Big Data and Analytics' started by Ghani Ahmad Warsi, Feb 3, 2019.

  1. Ghani Ahmad Warsi

    Alumni

    Joined:
    Jun 28, 2016
    Messages:
    9
    Likes Received:
    1
    Hi,

    I am trying to upload csv file into my mysql table on your lab.
    But it is not allowing me to upload file.

    PLease give me access ASAP.

    Below see below error.

    =============================================

    mysql> LOAD DATA INFILE '/home/ghaniwarsi_gmail/Social_Media_Part1.csv' INTO TABLE SMedia FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1
    LINES;
    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
    mysql> SHOW VARIABLES LIKE "secure_file_priv";
    +------------------+-----------------------+
    | Variable_name | Value |
    +------------------+-----------------------+
    | secure_file_priv | /var/lib/mysql-files/ |
    +------------------+-----------------------+
    1 row in set (0.00 sec)

    ================================================

    Even permission is denied when I try to upload file in /var/lib/mysql-files/ path.

    Regards,
    Ghani
     
    #1
  2. Neha_Pandey

    Neha_Pandey Well-Known Member
    Simplilearn Support Alumni

    Joined:
    Jun 7, 2018
    Messages:
    95
    Likes Received:
    0
    Hi Learner,

    You need to remove the headers so that there is only data in the file.

    I hope this helps. :)

    Regards,
    Neha Pandey
     
    #2
  3. Neha_Pandey

    Neha_Pandey Well-Known Member
    Simplilearn Support Alumni

    Joined:
    Jun 7, 2018
    Messages:
    95
    Likes Received:
    0
    Hi Learner,

    You can also use the below code.
    code- LOAD DATA LOCAL INFILE
    'D:/folder_name/myfilename.csv' INTO TABLE mail FIELDS TERMINATED BY ',' (fname,lname ,email, phone);

    Regards,
    Neha Pandey
     
    #3

Share This Page