Best practice for creating a data directory for MySQL

Yes, I create a separate ZFS filesystem for MySQL/MariaDB data, with recordsize=16k. I also create a separate zfs dataset for the Innodb log, with recordsize=128k (the zfs default).
I add this to /etc/mysql/my.cnf:

[mysqld]
skip-innodb_doublewrite
innodb_use_native_aio=0
innodb_use_atomic_writes=0

innodb_log_group_home_dir = /var/lib/mysql-log
bind-address = 0.0.0.0

/var/lib/mysql-log is where I mount the log filesystem.
I add these two external filesystems to a profile, which I then add to the container.

I don’t use an idmap. Instead, I change the ownership of the filesystem to match the uid/gid of the container’s mysql user. For my container, this is 1000111:1000115. The idmap may be better, because you can change it appropriate when moving the filesystem to a container with different mysql uid.

Using such external filesystems with containers has advantages and disadvantages. The disadvantage is that creating snapshots or copies of the container (e.g. for testing) requires more care, because you need to snapshot/clone the external filesystem too. The advantage is that you can manage the database data separately from the container OS, move it to another container, etc. I’ve been using external filesystems with several of my containers, and I try to thus separate the guest OS from my data.

1 Like