In this post I will try to explain how you can generate CSVs through MySQL queries in user's home directory so that only that user and MySQL has read/write access on that directory. For example, there is a 'zaeem' with home directory '/home/zaeem/'. If you try to generate CSVs in /home/zaeem then MySQL gives Errcode: 13 that it doesn't have permission to write on this directory. To resolve this you need to create a group and add both users 'zaeem and 'mysq' to that group and change group of '/home/zaeem' to new group and giver permissions on the directory, restart MySQL and your issue will be resolved. Following are the commands to accomplish that.
- useradd zaeem
- groupadd csv
- usermod -G csv mysql
- usermod -G csv zaeem
- chgrp -R csv zaeem/
- chmod 0770 -R /home/zaeem/
- service mysql restart
- Login to MySQL and try to generate CSV in /home/zaeem
Hope this will help.
Cheers!