简体   繁体   English

LOAD DATA INFILE 和用户访问

[英]LOAD DATA INFILE and user access

I am trying insert data from file into mysql table, I am use for this LOAD DATA INFILE , this is my php code我正在尝试将文件中的数据插入 mysql 表,我正在使用此LOAD DATA INFILE ,这是我的 php 代码

sql = " HERE LOAD DATA INFILE QUERY ...";
$sth = $db->prepare( $sql ); 
$sth->execute();

var_dump( $sth->errorInfo() );

Data is not loaded and errorInfo() shows that Access denied for user 'blabla'@'localhost' (using password: YES)数据未加载且 errorInfo() 显示Access denied for user 'blabla'@'localhost' (using password: YES)

But this user, which I connect to DB, has ALL PRIVILEGES.但是我连接到数据库的这个用户拥有所有权限。

Why this happened?为什么会这样? Where I am wrong?我哪里错了?

Try granting rights for files : 尝试授予文件权限:

GRANT FILE ON *.* TO user@localhost

You can read more on this here 你可以在这里阅读更多相关内容

As Stephan's answer rightly states, you need to grant the FILE privilege to the user who wants to load data from external files.正如 Stephan 的回答正确指出的那样,您需要向想要从外部文件加载数据的用户授予 FILE 权限。 This privilege needs to be granted by root or a user with appropriate grant privileges.此权限需要由 root 或具有适当授予权限的用户授予。

Note, that the FILE privilege is a global privilege.请注意,FILE 权限是全局权限。 See https://mariadb.com/kb/en/grant/参见https://mariadb.com/kb/en/grant/

When you use the command grant all privileges on <dbname>.* to <user>@<host>;当您使用该命令时,将grant all privileges on <dbname>.* to <user>@<host>; you are granting database privileges.您正在授予数据库权限。 Hence the file privilege will not be included in the grant statement.因此,文件权限不会包含在授权声明中。

After granting privileges, whether global or database or any level, it is always a good idea to execute command flush privileges;授予权限后,无论是全局还是数据库或任何级别,执行命令flush privileges; to ensure the changes are applied.以确保应用更改。

IMPORTANT: there is also a difference between the commands load data infile and load data local infile .重要提示:命令load data infileload data local infile之间也有区别。 As stated in the MariaDB documentation:如 MariaDB 文档中所述:

When you execute the LOAD DATA INFILE statement, MariaDB Server attempts to read the input file from its own file system.当您执行 LOAD DATA INFILE 语句时,MariaDB 服务器尝试从其自己的文件系统读取输入文件。 In contrast, when you execute the LOAD DATA LOCAL INFILE statement, the client attempts to read the input file from its file system, and it sends the contents of the input file to the MariaDB Server.相反,当您执行 LOAD DATA LOCAL INFILE 语句时,客户端尝试从其文件系统读取输入文件,并将输入文件的内容发送到 MariaDB 服务器。 This allows you to load files from the client's local file system into the database.这允许您将文件从客户端的本地文件系统加载到数据库中。

https://mariadb.com/kb/en/load-data-infile/ https://mariadb.com/kb/en/load-data-infile/

If you are attempting to load a CSV file from your home directory you must use load data local infile .如果您尝试从主目录加载 CSV 文件,则必须使用load data local infile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM