title: How can I get around MySQL Errcode 13 with SELECT INTO OUTFILE?
body: <p>I am trying to dump the contents of a table to a csv file using a MySQL SELECT INTO OUTFILE statement.  If I do:</p>
  
  <pre><code>SELECT column1, column2
  INTO OUTFILE 'outfile.csv'
  FIELDS TERMINATED BY ','
  FROM table_name;
  </code></pre>
  
  <p>outfile.csv will be created on the server in the same directory this database's files are stored in.  </p>
  
  <p>However, when I change my query to:</p>
  
  <pre><code>SELECT column1, column2
  INTO OUTFILE '/data/outfile.csv'
  FIELDS TERMINATED BY ','
  FROM table_name;
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>ERROR 1 (HY000): Can't create/write to file '/data/outfile.csv' (Errcode: 13)
  </code></pre>
  
  <p>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".</p>
  
  <p>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.</p>
  
  <p>This is MySQL 5.0.75 running on Ubuntu.  </p>