简体   繁体   中英

MySQL: Still can't LOAD DATA LOCAL INFILE '/path/to/file.txt' INTO TABLE test FIELDS TERMINATED BY '\n'

Using Ubuntu Server 14.04 x64 / PHP 5.5.9-1ubuntu4 (cli) w/ FPM / MySQL InnoDB version 5.5.35

I've created a PHP script that downloads a text file from a remote server and then attempts to import it with the LOAD DATA LOCAL INFILE '/path/to/file.txt' INTO TABLE test FIELDS TERMINATED BY '\\n'.

I've gone through the process of modifying the php.ini file:

[MySQL]
; Allow accessing, from PHP's perspective, local files with LOAD DATA statements
; http://php.net/mysql.allow_local_infile
mysql.allow_local_infile = On

I've modified my.cnf (both [mysql] and [mysqld] entries):

local-infile=1
local-infile

I've run MySQL from the terminal and then issue:

SET GLOBAL local_infile = 'ON';

I've manually started and stopped MySQL with:

sudo /etc/init.d/mysql start --enable-local-infile

After each of these commands I can run SHOW GLOBAL VARIABLES LIKE 'local_infile'; and it always says the value is ON. I have no problem whatsoever executing my LOAD DATA command from MySQL prompt but if I try to run the LOAD DATA stored in a PHP file it errors out with:

The used command is not allowed with this MySQL version

From what I've read, there seems to be a few who suggest to recompile PHP with "--with-mysql=/usr" but that seems like a real sledge hammer approach to me, maybe I'm wrong. I can issue ANY MySQL query except for that that from a PHP file. What am I doing wrong?

You have to write twice the following line into the file /etc/mysql/my.cnf

sudo gedit /etc/mysql/my.cnf

then under paragraph [mysql] and paragraph [mysqld]

add the following line :

local-infile=1

then save the file

then restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM