5

How to setup mysql on tmpfs ?

I am reading a tutorial in french, where the author do it this way :

1.) Create a tmpfs directory :

mkdir /var/tmpfs
mount -t tmpfs -o size=1G tmpfs /var/tmpfs
chown -R mysql:mysql /var/tmpfs/mysql

2.) Add it to fstab :

tmpfs  /var/tmpfs  tmpfs  nodev,nosuid,noexec,noatime,size=1G  0 0

3.) Copy MySQL to tmpfs (is ramfs here is correct?)

service mysql stop
cp -Rfv /var/lib/mysql /var/ramfs/
chown -R mysql:mysql /var/tmpfs/mysql

4.) Edit /etc/my.cnf

datadir /var/tmpfs/mysql

Then restart mysqld and you can optionally add a startup/stop script to backup the ram data to disk...

But I am not sure the above is right : did the writer of this tutorial mistake ramfs for tmpfs here ? He then goes on to use ramfs in the start/stop script, but what ramfs has to do there, isn't it really tmpfs only ?

2
  • Why would you do this? Jul 11, 2012 at 14:24
  • 2
    To speed up Drupal's SimpleTests, it's really necessary.
    – B2F
    Jul 11, 2012 at 17:49

2 Answers 2

5

Seems like it was really

cp -Rfv /var/lib/mysql /var/tmpfs/

Working great now.

2

Before you try doing this: take a look at mysql's "memory" storage engine. I would stick with that rather than having to deal with the many edge cases with e tmpfs.

http://dev.mysql.com/doc/refman/5.5/en/memory-storage-engine.html

we were considering the exact same scenario, but luckly ran across the memory engine, and have not had a problem since.

2
  • Don't you have to change every single database upgrade script in your app to use ENGINE = MEMORY this way? Seems impossible to do if you're running tests differently to live code. The tmpfs solution seems like the only one
    – Richard
    Jan 16, 2017 at 13:17
  • MySQL's "memory" storage engine does not support BLOB/TEXT fields. So for DB's with those, like the one I was working on, MEMORY storage is a non-starter. Jan 28, 2017 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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