load data infile is not allowed MariaDB

你离开我真会死。 提交于 2020-01-06 06:41:15

问题


I created a PHP script that imports posts from a CSV file into a WordPress website.

To do this, I first bulk import the posts into a table of the WP website database and then the PHP script creates the posts. The bulk insert MYSQL query I use is the following:

load data local infile '/var/www/vhosts/sitenamehere.test/test.csv' into table test_table character set latin1 fields terminated by ';' lines terminated by '\r\n' ignore 1 lines;

When I run the script from the server I get the following error:

"the used command is not allowed with this MariaDB version for the query load data local infile..."

The problem occurs only when I execute the script from the server, in fact if I run the same query from phpMyAdmin, it lets me import the file.

Since my scripts not only imports but also updates posts, the intention was to create a cron job so that the script is executed multiple times a day. Obviously this is not possible if I keep getting the same error.

I tried adding:

  • the line local-infile=1 under the section [client] and [mysqld] of my.cnf
  • the line mysql.allow_local_infile=On under the [mysql] section of my.cnf
  • the line mysql.allow_local_infile=On under the [MySQLi] section of php.ini located at /opt/plesk/php/7.1/etc

But nothing helped. Any ideas?


回答1:


The guide at https://mariadb.com/kb/en/library/load-data-infile/ says

If the local_infile system variable is set to 0, attempts to perform a LOAD DATA LOCAL will fail with an error message.

You best bet is to change the my.ini file that's being used.

Moreover the used database user needs the FILE privilege.




回答2:


You must add AllowLoadLocalInfile=true; to your MySQL/MariaDB server connection string when you want to load a local file.

If using something like a LOAD LOCAL INFILE command then add --local_infile=1 to the command itself and it should work.

In recent versions of both servers this functionality is disabled by default and should only be enabled when necessary.



来源:https://stackoverflow.com/questions/47940175/load-data-infile-is-not-allowed-mariadb

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