简体   繁体   中英

In MySQL, MyISAM, Is it possible to alter table with partition into multiple hard drive?

In MySQL, MyISAM, Is it possible to alter table with partition into multiple hard drive ?

My hard drive is nearly used up its disk space.

is there anyone facing this problem and how do you solve it?

Yes, it's possible to partition a table over multiple drives. Have a look at the official manual, which covers this subject in depth.

http://dev.mysql.com/doc/refman/5.5/en/partitioning.html

Here's an example to partition an existing table over multiple drives:

ALTER TABLE mytable
    PARTITION BY RANGE (mycolumn)(
     PARTITION p01 VALUES Less Than (10000)
       DATA DIRECTORY = "/mnt/disk1"
       INDEX DIRECTORY = "/mnt/disk1",
     PARTITION p02 VALUES Less Than (20000)
       DATA DIRECTORY = "/mnt/disk2"
       INDEX DIRECTORY = "/mnt/disk2",
     PARTITION p03 VALUES Less Than MAXVALUE
       DATA DIRECTORY = "/mnt/disk3"
       INDEX DIRECTORY = "/mnt/disk3"
    );

Mind that this needs NO_DIR_IN_CREATE to be off. It doesn't seem to work in windows, and it doesn't seem to work with InnoDB.

If you run out of diskspace on your last partition, you can split it with following statement:

ALTER TABLE mytable REORGANIZE PARTITION p03 INTO 
( 
    PARTITION p03 VALUES Less Than (30000)
       DATA DIRECTORY = "/mnt/disk3"
       INDEX DIRECTORY = "/mnt/disk3",
     PARTITION p04 VALUES Less Than MAXVALUE
       DATA DIRECTORY = "/mnt/disk4"
       INDEX DIRECTORY = "/mnt/disk4"
);

诀窍是像平常一样创建分区,将选定的分区移动到其他硬盘驱动器,并将它们符号链接回/var/lib/mysql

You can move the entire mysql data directory. Change the datadir option in /etc/mysql/my.cnf .

If you want to just move one database, you can stop the server, move the directory ( /var/lib/mysql/DATABASE_NAME ) somewhere else, then add a symlink to the new location ( ln -s NEW_LOCATION /var/lib/mysql/DATABASE_NAME ).

Make certain to make backups!!!!!! Before messing with this!!!!!

( mysqldump --all-databases as a user that has access to everything, root probably.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM