I am trying to dump the contents of a table to a CSV file using a MySQL SELECT INTO OUTFILE statement. If I do:
SELECT column1, column2
INTO OUTFILE 'outfile.csv'
FIELDS TERMINATED BY ','
FROM table_name;
outfile.csv will be created on the server in the same directory this database's files are stored in.
However, when I change my query to:
SELECT column1, column2
INTO OUTFILE '/data/outfile.csv'
FIELDS TERMINATED BY ','
FROM table_name;
I get:
ERROR 1 (HY000): Can't create/write to file '/data/outfile.csv' (Errcode: 13)
Errcode 13 is a permissions error, but I get it even if I change ownership of /data to MySQL: MySQL and give it 777 permissions. MySQL is running as user "MySQL".
Strangely I can create the file in /tmp, just not in any other directory I've tried, even with permissions set such that user MySQL should be able to write to the directory.
This is MySQL 5.0.75 running on Ubuntu.