Use tmpfs for MariaDB storage

24年 11月 8日 Friday
193 words
1 minutes

DISCLAIMER: I can't provide a convincing proof that tmpfs is the right choice for this needs, yet. So please keep skeptical while reading this post.

The rationale

On debugging or testing with database, I think it would be a great idea to reduce the disk I/O operation by using random access memory, and tmpfs is the choice that come into my mind.

HOWTO

First, create a mount point for mysql and its temporary directory, I'll use /mysql and /mysqltemp respectively, and optionally append the following line at the end of file of /etc/fstab to automatically mount it:

text
tmpfs   /mysqltmp	tmpfs   rw,gid=mysql,uid=mysql,size=100M,mode=0750,noatime   0 0
tmpfs   /mysql		tmpfs   rw,gid=mysql,uid=mysql,size=15G,mode=0750,noatime   0 0

feel free to adjust the size, exec sudo mount or if you don't prefer adding new entry to fstab:

text
mount -t tmpfs /<mount-point> -o size=<size>

stop the mariadb service and edit /etc/my.cnf:

text
[mysqld]
datadir=/mysql
tmpdir=/mysqltmp

and install the default config: mariadb-install-db --user=mysql --datadir=/mysql

and optionally copy the existing database while the service is not running: the default datadir location is /var/lib/mysql/.

if you don't want to reconfigure and just want fully migrate previous settings, follow this stackoverflow's answer.

finally, you can start the service again: systemctl start mariadb.

known problem - can't use existed tmpfs /tmp as datadir.

Title:Use tmpfs for MariaDB storage

Author:ReYuki

Link:https://www.reyuki.site/posts/use-tmpfs-for-mariadb-storage [copy]

Last updated:


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. You are free to share and adapt it, as long as you give appropriate credit, don’t use it for commercial purposes, and distribute your contributions under the same license. Provided under license CC BY-NC-SA 4.0