The used command is not allowed with this MariaDB version with local_infile ON

隐身守侯 提交于 2021-01-29 14:25:15

问题


I know, there are a couple of questions out there, that are focusing on the same Issue, but all suggested fixes are not working for me.

I am running a PHP script in which I a trying to insert a CSV file into my DB using LOAD DATA INFILE like this

$db = mysqli_init();
mysqli_options($db, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($db, $db_host, $db_username, $db_password, $database);

$sql = "LOAD DATA LOCAL INFILE '" . $tpl_vars['filename'] . "' " .
       "INTO TABLE " . $table_name . " " .
       "FIELDS TERMINATED BY '" . $tpl_vars['delimiter'] . "' " .
       "ENCLOSED BY '\"" . $tpl_vars['encapsulation'] . "' " .
       "LINES TERMINATED BY '\\n' " .
       ($tpl_vars['contains_header'] == 1 ? "IGNORE 1 ROWS" : "") . " " .
       "(" . $columns . ") " .
       $set;

$db->query($sql);

The resulting statement looks like thish and is syntactically right. All columns to exist in the table.

LOAD data local INFILE '/path/to/file/file.csv' 
INTO TABLE my_table
FIELDS TERMINATED BY ';' 
ENCLOSED BY '"' 
LINES TERMINATED BY '\n' 
IGNORE 1 rows (@category, @title, @price, @description) 
SET category = @category, title = @title, price = @price, description = @description;

The result I get is

The used command is not allowed with this MariaDB version.

Even if I run the statement in phpMyAdmin it results in

2000 - LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile

Because I do not have complete root access to my server I checked my php.ini using ini_get_all() and it returned

mysqli.allow_local_infile: {global_value: "1", local_value: "1", access: 4}

To check the my.cnf I ran SHOW VARIABLES on my DB. It returned

local_infile ON

As far as I can see, everything is configured totally fine to run LOAD DATA LOCAL INFILE. Am I missing something?

My user does have the following GRANTS

GRANT USAGE ON *.* TO 'user'@'localhost' IDENTIFIED BY PASSWORD 'asdf'
GRANT ALL PRIVILEGES ON `db`.* TO 'user'@'localhost'

I am on MariaDB 10.1.44 and PHP 5.5.38.


回答1:


It seems that the problem was, that my user did not have File grants.

GRANT FILE ON *.* TO 'user'@'localhost' IDENTIFIED BY PASSWORD 'asdf'

did the trick.



来源:https://stackoverflow.com/questions/61532908/the-used-command-is-not-allowed-with-this-mariadb-version-with-local-infile-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!