我正在尝试将xml文件的目录作为blob加载到数据库表中。每行都包含一个相应的blob文件。通过python脚本将文件加载到表中时,值将作为null插入。在mysql命令行中运行等效命令时也是如此。
有一次我能够在将一些文件夹权限更改为mysql之后插入值,但由于需要脚本权限,我不得不修改目录/ var / lib / mysql / foo的所有权,因此值被重新插入为null有效地打破了我写的剧本。我不记得必要的目录权限更改这样做。
以下是对该主题的讨论:
http://bugs.mysql.com/bug.php?id=38403
与
一起答案 0 :(得分:5)
确保:
父目录的许可示例:
mysql> \! ls -ld `dirname /home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg` drwxrwxr--. 2 jlam jlam 4096 May 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')) | +-------------------------------------------------------------------------------------------------------------+ | NULL | +-------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> \! chmod o+x /home/jlam/code/projectName/doc/filesForTesting/images mysql> \! ls -ld `dirname /home/jlam/code/projectName/doc/filesForTesting/images/imageTest01.jpg` drwxrwxr-x. 2 jlam jlam 4096 May 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 Enter password: mysql> show grants; +-----------------------------------------------------------------------------------------------------------------+ | Grants for eventCal@localhost | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'eventCal'@'localhost' IDENTIFIED BY PASSWORD '*xxxx' | | GRANT ALL PRIVILEGES ON `tmp`.* TO 'eventCal'@'localhost' | | GRANT ALL PRIVILEGES ON `eventCalTesting`.* TO 'eventCal'@'localhost' | | GRANT ALL PRIVILEGES ON `eventCal`.* TO 'eventCal'@'localhost' | | GRANT ALL PRIVILEGES ON `eventCal_categoryMigration`.* TO 'eventCal'@'localhost' | +-----------------------------------------------------------------------------------------------------------------+ 5 rows in set (0.00 sec) 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')) | +-------------------------------------------------------------------------------------------------------------+ | NULL | +-------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
在其他根会话中:
mysql> grant file ON *.* to eventCal@localhost; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
回到用户会话,我仍然无法加载文件
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')) | +-------------------------------------------------------------------------------------------------------------+ | NULL | +-------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
.....但如果我退出并重新登录:
mysql> exit Bye 16:40:14 (getImages) ~/code/projectName/doc/filesForTesting/images$ mysql -u eventCal -p eventCal Enter password: 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 +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
答案 1 :(得分:3)
我在这个问题上已经失去了一些时间。就我而言,问题与" my.ini"中定义的 secure_file_priv 变量有关。
来自MySQL文档:
如果secure_file_priv系统变量设置为非空 目录名称,要加载的文件必须位于该名称中 目录
所以,有两种方法:
1)删除此选项 2)使用默认文件夹上传文件(" C:\ ProgramData \ MySQL \ MySQL Server 5.7 \ Uploads")。我还必须在Windows中使用双斜杠。
答案 2 :(得分:2)
为了使加载文件正常工作,请确保为MySQL所有者和组授予所有权限。
chown mysql:mysql /var/lib/mysql/foo/*
chmod go+rw /var/lib/mysql/foo/*
答案 3 :(得分:2)
我将文件复制到MySQL可以访问的位置 。
要知道我使用的位置:
select @@secure_file_priv;
它给了我/var/lib/mysql-files/
。
没有任何其他作用:既不能关闭apparmor,也不能更改所有权和权限,也不只是授予file
特权。所以我回滚了大部分,但正确的目录仍然有效。就我而言。
我的消息来源是雷蒙德·尼兰(Raymond Nijland),在这里:https://dba.stackexchange.com/questions/190380/load-file-producing-null
答案 4 :(得分:0)
我在/var/lib/mysql/images
中复制了图像(在创建图像文件夹之后)并且它有效!
答案 5 :(得分:0)
这可能是由于SO安全限制造成的。事实上,我能够通过在AppArmour
中禁用MySQL配置文件来解决问题我遵循的程序是检查是否有为mysql加载的配置文件
sudo aa-status
然后禁用它
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
https://www.cyberciti.biz/faq/ubuntu-linux-howto-disable-apparmor-commands/
答案 6 :(得分:0)
Acubo用Null Blob插入解决了我的问题。在MySql my.ini文件中,将secure-file-priv设置为我不使用的特定文件夹,这就是为什么它忽略了LOAD_FILE中的路径的原因。 Acubo说要确保将安全文件专用设置设置为空。然后它将使用LOAD_FILE语句中的硬编码路径。
my.ini
保护文件私密性。由Frank Salinas修改2019/12/11 secure-file-priv必须为null才能查询除硬编码目录以外的目录
secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.7/Uploads"
secure-file-priv=""
答案 7 :(得分:0)
我在这里尝试了所有其他答案。经过反复试验,发现我的问题是secure-file-priv
根本没有设置为任何东西。当我将此值设置为my.conf中的目录路径并确保正确设置权限后,文件终于可以访问
添加到my.conf:
secure_file_priv="/test/"
我认为这个答案是特定于在Mac上运行的mysql