I've seen this question asked about a dozen times and the answers that seem to work for everyone are the same: add local-infile = 1
to [mysql]
, [mysqld]
, and add [client] loose-local-infile=1
to my.conf. I've done all of that as well as adding file permission to my DB user for . and I still get the same error.
I'm running MySQL 5.6 on a virtual Ubuntu 14.04 server. Can anyone let me know what I'm missing? I've got this working successfully on my live server which is a VPS running CentOS and MySQL 5.6 as well and I don't remember having to jump through any hoops to get it working, though it was some time ago that I set it up.
If it matters, I'm attempting this import through the below PHP function:
// Connect to a database without using prepared statements (for LOAD FILE feed commands)
// $query = query to execute; $rs = return a result set if true
function db_query_unprepared($query, $rs = false) {
// Create database connection
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if (!$link) {
print 'Error connecting to MySQL Server. Errorcode: ' . mysqli_connect_error();
exit;
}
// Execute the query
if ($rs) {
$queryresults = array();
$counter = 0;
if (mysqli_multi_query($link, $query)) {
do {
// Save results to an array
if ($result = mysqli_store_result($link)) {
while ($row = mysqli_fetch_assoc($result)) {
$queryresults[$counter][] = $row;
}
mysqli_free_result($result);
$counter++;
}
} while (mysqli_next_result($link));
}
else {
print mysqli_error($link);
}
}
else {
mysqli_multi_query($link, $query);
}
mysqli_close($link);
// Return the results
if (isset($queryresults)) {
return $queryresults;
}
}
That in turn is called like so:
db_query_unprepared('LOAD DATA LOCAL INFILE \'/path/to/mydatafile.csv' . '\' INTO TABLE feed_mydata FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' LINES TERMINATED BY \'\r\n\' IGNORE 1 LINES ( field1, field2, field3 )');