How to change owner of mount point

Solution 1:

You need to change the permissions of the mounted filesystem, not of the mount point when the filesystem is not mounted. So mount /var/lib/mysql then chown mysql.mysql /var/lib/mysql. This will change the permissions of the root of the MySQL DB filesystem.

The basic idea is that the filesystem holding the DB needs to be changed, not the mount point, unless its path has some issues, e.g. lib can only be read by root.

Solution 2:

also

mount device mount-point -o uid=foo -o gid=foo

if group need to be changed too


Solution 3:

Add uid and gid like these:

/dev/mapper/db-db  /var/lib/mysql ext3  relatime,rw,exec,uid=frank,gid=www-group        0       2

You can use actual user/groupnames (beware of spaces) or numeric uid, gid values. I added rw and exec which might further help you prevent access troubles (presuming you are on a development system, not a production server).

PS: For even more access (if desired), add ",dir_mode=0777,file_mode=0777"


Solution 4:

Make sure you change the permissions when the filesystem is not mounted - doing it while mounted has never worked for me.

Additionly, you can add the 'user' option to your fstab, example:

/dev/mapper/db-db   /var/lib/mysql    ext3    relatime,user        0       2

This should also mean that the mount command (if it needs to be called) won't need root privileges to mount that volume. Not changing your fstab will not stop you fixing your issue though!


Solution 5:

If you want to only do it as part of the mount command line, you can use the -o switch and do:

mount device mount-point -o uid=foo

That will change the owner of the mount point to user foo instead of root.