LOAD DATA LOCAL INFILE forbidden in… PHP

后端 未结 12 1130
无人共我
无人共我 2020-12-01 10:38

I am trying to use LOAD DATA INFILE to insert some records into a table. Unfortunately, it\'s not working.

Here are some details

If I use this i

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 11:04

    I didn't get the exact error you get, but you need no ensure the following:

    Enable by adding to your my.cnf:

    [mysql]
    local-infile=1
    
    [mysqld]
    local-infile=1
    

    Tell the connection in PHP that it may use LOCAL INFILE

    Using mysql:

    mysql_connect(server,user,code,false,128); // 128 enables LOCAL INFILE
    mysql_select_db(database);
    

    Using mysqli:

    $conn = mysqli_init();
    mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
    mysqli_real_connect($conn,server,user,code,database);
    

    Give MySQL user FILE permission

    When using LOCAL this shouldn't be necessary, though. LOCAL says that the file is located on the client server (where you have PHP is installed), otherwise it looks at server location (where MySQL is installed).

    GRANT FILE ON *.* TO 'mysql_user'@'localhost' 
    

提交回复
热议问题