MySQL: Enable LOAD DATA LOCAL INFILE

后端 未结 18 1008
北海茫月
北海茫月 2020-11-22 09:30

I\'m running Mysql 5.5 on Ubuntu 12 LTS. How should I enable LOAD DATA LOCAL INFILE in my.cnf?

I\'ve tried adding local-infile in my config at various places but I\'

相关标签:
18条回答
  • 2020-11-22 09:39

    I am using xampp v3.2.4 and mysql server 8.0.20.

    I added local-infile=1 to [mysql] and [mysqld] in the file "my.ini". The file is located at "C:\xampp\mysql\bin\my.ini".

    Then I inserted the data from csv file using the following code LOAD DATA INFILE .... It is important to move LOCAL. Otherwise it won't work.

    Thanks for all suggestions above. A combination finally worked out for me.

    0 讨论(0)
  • 2020-11-22 09:42

    See below image...

    I've added --local-infile=1 to normal mysql command mysql -u root -p

    So total line would be :

    mysql --local-infile=1 -u root -p

    0 讨论(0)
  • 2020-11-22 09:44

    I solved this problem on MySQL 8.0.11 with the mysql terminal command:

    SET GLOBAL local_infile = true;
    

    I mean I logged in first with the usual:

    mysql -u user -p*
    

    After that you can see the status with the command:

    SHOW GLOBAL VARIABLES LIKE 'local_infile';
    

    It should be ON. I will not be writing about security issued with loading local files into database here.

    0 讨论(0)
  • 2020-11-22 09:44

    In case if Mysql 5.7 you can use "show global variables like "local_infile" ;" which will give the local infile status ,You can turn it on using "set global local_infile=ON ; ".

    0 讨论(0)
  • 2020-11-22 09:49

    This went a little weird for me, from one day to the next one the script that have been working since days just stop working. There wasn´t a newer version of mysql or any kind of upgrade but I was getting the same error, so I give a last try to the CSV file and notice that the end of lines were using \n instead of the expected ( per my script ) \r\n so I save it with the right EOL and run the script again without any trouble.

    I think is kind of odd for mysql to tell me The used command is not allowed with this MySQL version since the reason was completely different.

    My working command looks like this:

    LOAD DATA LOCAL INFILE 'file-name' IGNORE INTO TABLE table-name CHARACTER SET latin1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES.
    
    0 讨论(0)
  • 2020-11-22 09:50

    Another way is to use the mysqlimport client program.

    You invoke it as follows:

    mysqlimport -uTheUsername -pThePassword --local yourDatabaseName tableName.txt
    

    This generates a LOAD DATA statement which loads tableName.txt into the tableName table.

    Keep in mind the following:

    mysqlimport determines the table name from the file you provide; using all text from the start of the file name up to the first period as the table name. So, if you wish to load several files to the same table you could distinguish them like tableName.1.txt, tableName.2.txt,..., etc, for example.

    0 讨论(0)
提交回复
热议问题