确保:
- 父目录有执行权限
- 必须明确授予 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'))
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| FFD8FFE1001845786966000049492A00080000000000000000000000FFEC00114475636B7900010004000000500000FFE10407687474703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F003C3F787061636B657420626567696E3D22EFBBBF222069643D2257354D304D7043656869487
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
用户权限示例:
16:38:09 (getImages) ~/code/projectName/doc/filesForTesting/images$ mysql -u eventCal -p eventCal
输入密码:
mysql> 显示授权;
+-------------------------------------------------- -------------------------------------------------- --------------+
| eventCal@localhost 的赠款 |
+-------------------------------------------------- -------------------------------------------------- --------------+
| 将 *.* 上的使用授权给 'eventCal'@'localhost' 由密码 '*xxxx' 识别 |
| 授予 `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'))
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------
| FFD8FFE1001845786966000049492A00080000000000000000000000FFEC00114475636B7900010004000000500000FFE10407687474703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F003C3F787061636B657420626567696E3D22EFBBBF222069643D2257354D304D7043656869487
+-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------