Thursday 7 March 2019

MySQL Can't create/write to file (Errcode: 13)

I wanted to export a table from MySQL to CSV format, so I wrote the following MySQL to a file:

use mydb;

select *
from mytab
into outfile '/folder/myfile.csv'
fields terminated by ','
enclosed by '"'
lines terminated by '\n';

I then ran the following command line:

sudo mysql -u root < myExport.sql

This generated the following error:

ERROR 1 (HY000): Can't create/write to file '/folder/myfile.csv' (Errcode: 13)

After searching for answers to no avail, I then changed the MySQL code as follows:

select *
from mytab
into outfile 'myfile.csv'
fields terminated by ','
enclosed by '"'
lines terminated by '\n';

I then re-ran the above command line command and used the following Linux command to search the entire file system for the file:

find -name myfile.csv

It found the file in /var/lib/mysql/mydb.

No comments: