Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying data directory for a specific database in mysql

I have a mysql database with 4 different databases. 1 of the databases has a lot of read/write activity that would benefit from being run on ramdisk. Due to the nature of the data layout and types of reads needed, memcached is not an effective option here. Therefore, I would like to run one of the databases in a ramdisk (data persistence is not an issue here).

The question: Is there anyway to set the data directory for just one table in a mysql database? I want 3 of the databases to have a data directory on my harddrive, and the other one pointed towards a directory in a ramdisk. If not, how could I install two instances of mysql on the same server (I am using Ubuntu).

Btw: I am aware of the MEMORY engine but that barely improve performance (doesn't seem to truly be running in memory).

EDIT:

I accidentally asked to specify the data directory for a table. What I actually meant was to ask how to specify the data directory for a 1 out of 4 databases in a mysql installation. The post has been updated to reflect this correction.

like image 465
user396404 Avatar asked Mar 04 '26 07:03

user396404


1 Answers

For MyISAM tables, you can just provide a DATA DIRECTORY & INDEX DIRECTORY clause in your CREATE TABLE statement (if you partition your table, you'll have to set it per partition I believe).

$ mkdir /tmp/datadir
$ sudo chown mysql:mysql /tmp/datadir/
$ mysql
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table otherlocation (id int) ENGINE=MyISAM, DATA DIRECTORY='/tmp/datadir', INDEX DIRECTORY='/tmp/datadir';

Query OK, 0 rows affected (0.01 sec)
mysql> Bye
$ ls -lah /tmp/datadir/
total 496K
drwxr-xr-x  2 mysql mysql 4.0K Oct 18 00:57 .
drwxrwxrwt 32 root  root  484K Oct 18 00:55 ..
-rw-rw----  1 mysql mysql    0 Oct 18 00:57 otherlocation.MYD
-rw-rw----  1 mysql mysql 1.0K Oct 18 00:57 otherlocation.MYI
like image 120
Wrikken Avatar answered Mar 05 '26 19:03

Wrikken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!