使用加载数据插入查询时出现错误。
"load data infile '/home/bharathi/out.txt' into table Summary"
此文件位于 位置。但是 mysql 抛出以下错误。 错误 29 (HY000):找不到文件“/home/bharathi/out.txt”(错误代码:13)
show variables like 'data%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
数据目录指向根权限文件夹。我无法更改此变量,因为它是只读的。
如何进行加载数据infile操作?
我尝试更改文件权限、加载本地文件中的数据。它不会工作。
最佳答案
根据 LOAD DATA INFILE
Syntax 记录:
For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use
LOAD DATA INFILE
on server files, you must have theFILE
privilege. See Section 6.2.1, “Privileges Provided by MySQL”. For non-LOCAL
load operations, if thesecure_file_priv
system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.
因此,您应该:
确保您的 MySQL 用户具有
FILE
权限,并且假设未设置secure_file_priv
系统变量:使文件对所有人都可读;或者
将文件移动到数据库目录。
否则,使用
LOCAL
关键字让您的客户端读取文件并将其传输到服务器。但是,请注意:LOCAL
works only if your server and your client both have been configured to permit it. For example, ifmysqld
was started with--local-infile=0
,LOCAL
does not work. See Section 6.1.6, “Security Issues withLOAD DATA LOCAL
”.
关于MySQL : Load data infile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12421312/