Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have moved mysql data directory to another disk, so now /var/lib/mysql is just a mount point to another partition. We set the owner of the /var/lib/mysql directory to mysql.mysql.

But everytime we mount the partition, the ownership changes to root.root. Because of this, we couldn't create additional MySQL database.

Our fstab entry:

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

How to change the owner of mount point to user other than root?

share|improve this question
add comment

6 Answers

up vote 11 down vote accepted

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.

share|improve this answer
    
This actually worked for me :) Thank you! –  Arie K Jul 11 '09 at 16:22
add comment

also

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

if group need to be changed too

share|improve this answer
1  
Where the uid foo is the name of the user you want to be the owner of the mount point. And gid foo is the name of the user group, generally the same as the user name. In doubt just type ls -l in your home directory and check the first and second names respectively. –  Zequez Sep 12 '12 at 17:35
add comment

Add uid and gid like these:

/dev/mapper/db-db  /var/lib/mysql ext3  realtime,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: I assume "relatime" means realtime. Not sure what this is good for. Also hope the very last 2 is intentional.

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

share|improve this answer
    
No, it's relatime. lwn.net/Articles/244829 –  endolith Aug 13 '12 at 16:45
add comment

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!

share|improve this answer
add comment

I usually do this on empty unmounted directory

chmod 777 <directory>

Then do

chown -R mysql.mysql <directory>

Then in /etc/fstab do

<device>    <directory>  ext3   user,defaults 0 2

Then use

mount -a

to mount all filesystems listed in /etc/fstab.

This works for me. Give it a try

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.