1

I want to use a separate volume for my mysql folder. Now there are several options:

  • creating a symlink
  • mounting via fstab
  • reconfiguring /etc/mysql/mysql.cnf and setting another data dir

Are there any advantages for one over the other. I'd prefer for the OS thinking that mysql folders are still the defaults as installed. So configuring a different data dir location is probably not the best option.

Would you rather go for symlink or fstab?

2 Answers 2

2

Some thoughts on the three approaches:

  1. symlink – this makes it easy for your fellow admins to see what's going on. (I seem to have misremembered update issues when the package manager sees a symlink where it expects a file or directory.)

  2. fstab – this will have the smallest impact, in my opinion. Just remember it's a good idea to make the mountpoint, i.e. the empty /var/lib/mysql on the root partition, immutable with chattr +i /var/lib/mysql, so that things fail hard if for some reason the data volume is not mounted, instead of filling up your drive.

  3. reconfiguring my.cnf – this will have minimal impact, unless you use tools that blindly assume things are in /var/lib/mysql. And there's always one more tool that you hadn't thought of, plus SELinux/Apparmor, plus logrotate, ….

None of these are "OMG, you will be doomed!", in my opinion. In some cases (multiple daemons on the same server), you'll need multiple my.cnfs anyway. Otherwise, I'd probably go with a mount or bind-mount.

1

I prefer to use fstab. In another case, do not forget about the apparmor rules

5
  • So in case I use fstab, no changes have to be made in apparmor, right? Could you maybe give an example for the correct fstab entry? Feb 6, 2020 at 9:25
  • Does it matter if I use ext4 default 0 2, or just none bind 0 0? My drive is already mounted via fstab to the folder /data, so I would like to create a additional mountpoint for /data/mysql /var/lib/mysql <properties> Feb 6, 2020 at 9:38
  • Yes, you are right. Example string in fstab: /dev/sdb1 /var/lib/mysql ext4 default 0 2
    – Yakim
    Feb 6, 2020 at 10:03
  • I mean, is there an important different using ext4 defaults 0 0 instead of just none bind 0 0? Feb 6, 2020 at 10:07
  • 1
    It depends on what you are mounting. If you want to mount new partition - use variant ext4 defaults 0 0 In another case (you mount folder from existing partition) - use none bind 0 0
    – Yakim
    Feb 6, 2020 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .