问题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了。
做事的人,永远都关注一个个具体的问题。