문제

I am running a windows machine for local development and attempting to load large csv files into mysql. My code looks like this:

$sql_query = 'LOAD DATA LOCAL 
    INFILE "' . $tempLoc . '"
    INTO TABLE users
    FIELDS
    TERMINATED BY " "
    ENCLOSED BY "\'"
    LINES
    TERMINATED BY "\\n"                                
    (
     id,
     name,
     value 
    )';

$statement = $this->adapter->query($sql_query);
$resultSet = $statement->execute();
$this->adapter->getDriver()->getConnection()->commit();

When I load the file I got this error:-

"PDOStatement::execute() [pdostatement.execute]: LOAD DATA LOCAL INFILE forbidden in..."

I have searched for an answer, but I have not been able to resolve the issue. But when i connect the db with local db in my local m/c(ie, localhost with root) it runs well

  • my application is in local machine
  • DB is connected to another server
도움이 되었습니까?

해결책

  1. Make sure the server allows LOAD DATA LOCAL INFILE

    [server]local-infile=1

  2. Make sure that your MySQL user has 'FILE' privilege

  3. Set the PDO attribute in your PHP script,

    $pdo = new PDO($dsn, $username, $password, array(PDO::MYSQL_ATTR_LOCAL_INFILE=>1))

다른 팁

When you use LOAD DATA LOCAL, you're telling the MySQL server process to open a local file, on its own file system, and read it. Most MySQL operations use a TCP/IP connection between your client and the MySQL server to send and receive all data. But this operation is different.

If your client code is running on one machine and the server is running on another, this won't work unless they are sharing a file system. Hint: if you're using one of those $5 per month hosting services, this probably won't work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top