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:
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:
mount -t tmpfs /<mount-point> -o size=<size>
stop the mariadb service and edit /etc/my.cnf
:
[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.