问题描述
我想使SQL LOAD_FILE 函数正常工作,并且已经阅读了有关此问题的每个问题/解答+文档,但这是正在发生的事情.
I want to get SQL LOAD_FILE function to work and have read every single question/answer + documentation about this, but here is what's been happening.
当我想从主目录中 LOAD_FILE 时:
mysql> SELECT LOAD_FILE('/home/myuser/somefile.txt');
+----------------------------+
| LOAD_FILE('/home/myuser/somefile.txt') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
因此,在获得此信息之后,我认为问题可能出在MySQL无法访问我的主目录.我尝试运行此程序,效果很好:
So after getting this, I thought maybe the problem is that MySQL cannot access my home directory. And I tried running this, which worked fine:
SELECT LOAD_FILE('/etc/mysql/my.cnf');
然后SELECT LOAD_FILE('/etc/passwd');
也可以正常工作.
所以我说了,这是一个文件/文件夹读取/所有权许可问题.因此,我将文件移至/etc/mysql/中,但仍然无法正常工作.我已经尝试过chown mysql:mysql somefile.txt
,但仍然没有运气:
So I said gotcha, it's a file/folder read/ownership permission problem. So, I moved my file into /etc/mysql/ but then it still didn't work. I've tried chown mysql:mysql somefile.txt
but still, I had no luck:
mysql> SELECT LOAD_FILE('/etc/mysql/somefile.txt');
+----------------------------+
| LOAD_FILE('/etc/mysql/somefile.txt') |
+----------------------------+
| NULL |
+----------------------------+
1 row in set (0.00 sec)
P.S. 1..所有用户组均可读取所有文件,因此无需chmod.但是,如果您要询问的话,我什至尝试了 chmod 777 . 2..我检查了,在MySQL中未设置secure-file-priv变量,因此,不,LOAD_FILE不限于任何路径.
P.S.1. All files are readable by all user groups, so no need to chmod. But I've even tried chmod 777 if you'd like to ask.2. I checked, secure-file-priv variable is not set up in MySQL, so no, LOAD_FILE is not restricted to any path.
任何想法在这里可能是什么问题?
Any ideas what might be the problem here?
推荐答案
我发现这与AppArmor有关.我为MySQL禁用了AppArmor,它起作用了.对于有相同问题的人,请在这里阅读: http://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/
I found out that it has to do with AppArmor. I disabled AppArmor for MySQL and it worked.For people having the same problem, please read here: http://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/
这篇关于MySQL LOAD_FILE返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!