MySQL: Enable LOAD DATA LOCAL INFILE

后端 未结 18 1007
北海茫月
北海茫月 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:53

    For those of you looking for answers to make LOAD DATA LOCAL INFILE work like me, this might probably work. Well it worked for me, so here it goes. Install percona as your mysql server and client by following the steps from the link. A password will be prompted for during the installation, so provide one that you'll remember and use it later. One the installation is done, reboot your system and test if the server is up and running by going to the terminal and typing mysql -u root -p and then the password. Try running the command LOAD DATA LOCAL INFILE now.. Hope it works :)

    BTW I was working on Rails 2.3 with Ruby 1.9.3 on Ubuntu 12.04.

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

    Ok, something odd is happening here. To make this work, do NOT need to make any configuration changes in /etc/mysql/my.cnf . All you need to do is to restart the current mysql service in terminal:

    sudo service mysql restart
    

    Then if I want to "recreate" the bug, I simply restart the apache service:

    sudo service apache2 restart
    

    Which can then be fixed again by entering the following command:

    sudo service mysql restart
    

    So, it appears that the apache2 is doing something to not allow this feature when it starts up (which is then reversed/corrected if restart the mysql service).

    Valid in Debian based distributions.

    service mysqld restart
    service httpd restart
    

    Valid in RedHat based distributions

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

    Add local_infile in both client and mysqld section.

    [client]
    local_infile=1
    ...
    
    [mysqld]
    local_infile=1
    ...
    

    Tested in MySQL 8.x both in Windows and Linux.

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

    All: Evidently this is working as designed. Please see new ref man dated 2019-7-23, Section 6.1.6, Security Issues with LOAD DATA LOCAL.

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

    I used below method, which doesn't require any change in config, tested on mysql-5.5.51-winx64 and 5.5.50-MariaDB:

    put 'load data...' in .sql file (ex: LoadTableName.sql)

    LOAD DATA INFILE 'D:\\Work\\TableRecords.csv' INTO TABLE tbl1 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (col1,col2);
    

    then:

    mysql -uroot -pStr0ngP@ss -Ddatabasename -e "source D:\Work\LoadTableName.sql"
    
    0 讨论(0)
  • 2020-11-22 10:02

    if your csv file located same with db, you need to remove LOCAL in LOAD DATA INFILE, or you will get the error

    The used command is not allowed with this MySQL version

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