SELECT INTO OUTFILE
fails for a CIFS-mounted directory (/mnt/backup/test
) but works for a normal directory (/tmp/tests
).
mysql> select * from mytable into outfile '/tmp/tests/mytable.txt';
Query OK, 3723 rows affected (0.05 sec)
mysql> select * from mytable into outfile '/mnt/backup/test/mytable.txt';
ERROR 1 (HY000): Can't create/write to file '/mnt/backup/test/mytable.txt' (Errcode: 2)
The mysql
user has no problem writing to /mnt/backup/test/mytable.txt
:
root:~# su - -s /bin/bash mysql
mysql:~$ touch /mnt/backup/test/mytable.txt
mysql:~$ ls -l /mnt/backup/test/mytable.txt
-rw-r--r-- 1 root root 0 2009-11-16 10:48 /mnt/backup/test/mytable.txt
The CIFS directory /mnt/backup
is mounted with : rw,noperm,user=****,password=****
Since the -T
option of mysqldump
makes use of it, what options (Mysql/CIFS) are needed for SELECT INTO OUTFILE
to work with my CIFS-mounted directory ?
Update:
Interestingly, an strace
of the mysqld
process did indeed reveal a access control failure as Michael suggested. But I still don't know why. A simple Perl script launched as mysql
calls the same syscall with no problem.
Extract of mysqld strace
open("/mnt/backup/tests/bugs.1.txt", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0666)
= -1 EACCES (Permission denied)
Extract of perl strace
open("/mnt/backup/tests/bugs.32064.txt", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0666) = 3
Note that the directory /mnt/backup/tests
was emptied before each run.
Actually the problem was AppArmor.
Adding
/mnt/backup/** w
to/etc/apparmor.d/usr.sbin.mysqld
and restarting it (/etc/init.d/apparmor restart
) solved the problem.That error might mean one of two things, the file might already exist or it is in fact a permissions problem (in spite of your example showing it isn't a permission problem, I believe it actually is).
Additionally, when you run 'su' with the '-' option to simulate their environment, you need to specify that as the last option to su.