想执行一个如下命令:
mysql -h127.0.0.1 -uuser -ppwd db -e "select id,* from table order by id into outfile '/data/table_1' FIELDS TERMINATED BY '\0' LINES TERMINATED BY '\b' "抛ERROR 1 (HY000) at line 1: Can't create/write to file '/data/192.168.0.103-t1132_1' (Errcode: 13) 错误。执行上述命令的是用户:aliang
系统是:2.6.38-8-generic-pae #42-Ubuntu无论把/data目录改成chmod 777权限还是mysql.mysql用户和组错误照旧。
解决方法:
sudo vi /etc/apparmor.d/usr.sbin.mysqld在里面添加/data的可写目录,如下:.../usr/sbin/mysqld { ... /var/log/mysql/ r, /var/log/mysql/* rw, /var/run/mysqld/mysqld.pid w, /var/run/mysqld/mysqld.sock w, /data/* rw,}然后重新载入:sudo /etc/init.d/apparmor reload/restart还需要重启mysql,否则会出些莫名其妙的错误,如:ERROR 1286 (42000) at line 1: Unknown table engine 'InnoDB'重启mysql:
sudo service mysql stop sudo service mysql start还有最后一定,把/data目录改成aliang.mysql用户和组,不然/data目录下生成的mysql.mysql文件是没权限删除的:
rm: cannot remove `/data/table_1': Operation not permitted改成后的路径情况如下:drwsrwsrwt 2 aliang mysql 4096 2011-08-02 16:15 data/如果是Linux下,我想情况应该类似,但如果有selinux对目录设置了安全权限,还需要对selinux进行相应设置。