Recently when I am exporting mysql command output to csv file I got following error.
ERROR 1 (HY000): Can’t create/write to file (Errcode: 13)
Here I am trying to write output to /home/someuser/somefile.csv I got this error.
After exploring a bit about the error I got to know is instead of writing to /home/someuser/somefile.csv we have to write to file /tmp/somefile.csv.
So I changed the output file to /tmp/somefile.csv in my sql command and its worked.
The reason for the error is permissions. While writing mysql command output into a directory we need have all permissions to that directory.
By default /tmp directory in Linux will have all permissions(777), so we need to write into /tmp directory.