8

我正在这样做,SELECT LOAD_FILE("/home/user/domains/example.com/public_html/robots.txt") AS tmp FROM tmpTable但它返回 NULL。我如何检查这是因为我没有 FILE 权限还是其他原因?MySQL不会给出错误。(我正在使用 PHP)

任何有 LOAD_FILE 经验的人,请告诉我有关该功能的信息:)

<?php
$result = mysql_query('SELECT LOAD_FILE("/home/user/domains/example.com/public_html/robots.txt") AS tmp FROM tmpTable') or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
var_dump( $row['tmp'] );
}
4

3 回答 3

5

可以在这里找到一个非常丑陋的解决方法:

http://angkatbahu.blogspot.com.es/2011/03/mysql-loadfile-function-in-ubuntu-it_12.html

如果将要加载的文件放在 /var/lib/mysql/all_images 目录中,它可以工作!

在 ubuntu 12.10 中测试(不,将文件 chomd'ing 给 mysql 用户,没有用)

于 2012-12-29T12:20:50.643 回答
4
于 2011-01-05T18:26:46.187 回答
1

要查看您拥有的权限,请使用show grants.

我已经记录了一些额外的命令,你可以使用它来检查你是否满足这里的条件:

http://pastebin.com/Dvsdxh9Y

我将对文档进行补充。确保:

  • 父目录有执行权限
  • 必须明确授予 FILE 特权。(GRANT FILE on . TO user@localhost)
  • 您已刷新权限
  • 您已注销并重新登录

父目录的权限示例:

mysql>\! ls -ld`目录名/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg`
drwxrwxr--。2 jlam jlam 4096 5 月 12 日 14:22 /home/jlam/code/projectName/doc/filesForTesting/images

mysql> select hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/image

Test01.jpg'));
+-------------------------------------------------- -------------------------------------------------- ----------+
| hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg')) |
+-------------------------------------------------- -------------------------------------------------- ----------+
| 空 |
+-------------------------------------------------- -------------------------------------------------- ----------+
一组中的 1 行(0.00 秒)



mysql>\! chmod o+x /home/jlam/code/projectName/doc/filesForTesting/images
mysql>\! ls -ld`目录名/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg`
drwxrwxr-x。2 jlam jlam 4096 5 月 12 日 14:22 /home/jlam/code/projectName/doc/filesForTesting/images
mysql> select hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'));
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'))                                                                                                                                
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| FFD8FFE1001845786966000049492A00080000000000000000000000FFEC00114475636B7900010004000000500000FFE10407687474703A2F2F6E732E61646F62652E636F6D2F786​​1702F312E302F003C3F787​​061636B657420626567696E3D22EFBBBF222069643D2257354D304D7043656869487
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------

用户权限示例:

16:38:09 (getImages) ~/code/projectName/doc/filesForTesting/images$ mysql -u eventCal -p eventCal
输入密码:

mysql> 显示授权;
+-------------------------------------------------- -------------------------------------------------- --------------+
| eventCal@localhost 的赠款 |
+-------------------------------------------------- -------------------------------------------------- --------------+
| 将 *.* 上的使用权授予 'eventCal'@'localhost' 由密码 '*xxxxx' 识别 |
| 授予 `tmp` 上的所有权限。* 到 'eventCal'@'localhost' |
| 授予 `eventCalTesting` 上的所有权限。* 到 'eventCal'@'localhost' |
| 授予 `eventCal` 上的所有权限。* 到 'eventCal'@'localhost' |
| 授予 `eventCal_categoryMigration` 上的所有权限。* 到 'eventCal'@'localhost' |
+-------------------------------------------------- -------------------------------------------------- --------------+
5 行一组(0.00 秒)

mysql> select hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'));
+-------------------------------------------------- -------------------------------------------------- ----------+
| hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg')) |
+-------------------------------------------------- -------------------------------------------------- ----------+
| 空 |
+-------------------------------------------------- -------------------------------------------------- ----------+
一组中的 1 行(0.00 秒)

在其他根会话中:

mysql> 将文件 ON *.* 授予 eventCal@localhost;
查询正常,0 行受影响(0.00 秒)

mysql> 刷新权限;
查询正常,0 行受影响(0.00 秒)

回到用户会话,我仍然无法加载文件

mysql> select hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'));
+-------------------------------------------------- -------------------------------------------------- ----------+
| hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg')) |
+-------------------------------------------------- -------------------------------------------------- ----------+
| 空 |
+-------------------------------------------------- -------------------------------------------------- ----------+
一组中的 1 行(0.00 秒)

.....但是如果我注销并重新登录:

mysql>退出
再见

16:40:14 (getImages) ~/code/projectName/doc/filesForTesting/images$ mysql -u eventCal -p eventCal
输入密码:

mysql> select hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'));
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| hex(LOAD_FILE('/home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg'))                                                                                                                                
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| FFD8FFE1001845786966000049492A00080000000000000000000000FFEC00114475636B7900010004000000500000FFE10407687474703A2F2F6E732E61646F62652E636F6D2F786​​1702F312E302F003C3F787​​061636B657420626567696E3D22EFBBBF222069643D2257354D304D7043656869487
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------

于 2014-05-12T20:31:00.227 回答