demo开发之问题01mysql中的load_file函数返回null

问题1:无法使用load_file("filepath")向db写入文件。

解法:

1) API中的定义

Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host,  (1)you must specify the full path name to the file(注意用“”包围文件地址) and (2)you must have the FILE privilege(修改权限 chmod 777 filepath). (3)The file must be readable by all and (4)its size less than max_allowed_packet bytes(使用show variables like “变量名” 查看系统变量的值 ). (5)If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory(修改secure_file_priv的值 首先使用 vim /etc/mysql/my.cnf,然后添加一下内容:[mysqld] secure_file_priv = "",最后使用show variables like "变量名" 查看其值是否为empty).If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns NULL

2)完成1)中的所有操作后,使用以下命令关闭ubuntu内apparmor对mysql的protection,便能完成正常load_file

 sudo apparmor_status  返回以下内容

apparmor module is loaded.
6 profiles are loaded.
6 profiles are in enforce mode.
   /sbin/dhclient
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/connman/scripts/dhclient-script
   /usr/sbin/mysqld
   /usr/sbin/ntpd
   /usr/sbin/tcpdump
0 profiles are in complain mode.
2 processes have profiles defined.
2 processes are in enforce mode.
   /usr/sbin/mysqld (27816) 
   /usr/sbin/ntpd (31952) 
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.

sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/

sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld  

完成上边三个操作后,就能成功使用load_file了。

做事的人,永远都关注一个个具体的问题。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值