开发者

Specifying data directory for a specific database in mysql

开发者 https://www.devze.com 2023-01-20 17:25 出处:网络
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

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 anywa开发者_如何学运维y 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.


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


You can move the files to the ramdisk and create symlink to their original location.

0

精彩评论

暂无评论...
验证码 换一张
取 消