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.

link|improve this question

In the interest of troubleshooting does redirecting the std out to a file on that drive work? i.e. mysqldump > /mnt/backup/test/outfile.sql work? – Catherine MacInnes Nov 16 '09 at 21:51
Yes. Actually that's how I do it right now. – Steve Schnepp Nov 17 '09 at 6:03
Ok, now I am seriously stumped. Sounds like su - isn't faithfully emulating the environment, possible because of Michael's suggestion about the - needing to be the last option. – Catherine MacInnes Nov 17 '09 at 19:13
feedback

2 Answers

up vote 1 down vote accepted

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.

link|improve this answer
feedback

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.

link|improve this answer
touch works the same with su -s /bin/bash mysql - – Steve Schnepp Nov 17 '09 at 8:38
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.