Here is a checklist to rule out this nasty bug:
1. Grant FILE user privileges in MySQL, phpMyAdmin sharing does not apply to this privilege:
GRANT FILE ON *.* TO 'db_user'@'localhost';
2- Change my.cnf in / etc / mysql / or your mysql path:
[mysql] local-infile=1 [mysqld] local-infile=1
3- In php.ini in / etc / php5 / cli / or similar:
mysql.allow_local_infile = On
Perhaps you can run ini_set in your script:
ini_set('mysql.allow_local_infile', 1);
4- The database handler library must use the correct parameters.
<i> PDO
new PDO('mysql:host='.$db_host.'.;dbname='.$db_name, $db_user, $db_pass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1));
<i> MySQLi
$conn = mysqli_init(); mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true); mysqli_real_connect($conn,server,user,code,database);
5- Make sure the INFILE command uses the absolute path to the file and that it exists:
$sql = "LOAD DATA INFILE '".realpath(is_file($file))."'";
6- Make sure the target file and parent directory are read by PHP and MySQL.
$ sudo chmod 777 file.csv
7- If you work locally, you can remove LOCAL from your SQL:
LOAD DATA INFILE
Instead:
LOAD DATA LOCAL INFILE
Note: Remember to restart the MySQL and PHP services if you edit their configuration files.
Hope this helps someone.