Tuesday, November 2, 2010

How to generate CSV in user's home directory through mysql

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.

  1. useradd zaeem
  2.  
  3. groupadd csv
  4. usermod -G csv  mysql
  5. usermod -G csv  zaeem
  6. chgrp -R csv zaeem/
  7. chmod 0770 -R /home/zaeem/
  8. service mysql restart
  9. Login to MySQL and try to generate CSV in /home/zaeem
Hope this will help. 
Cheers!