Home >Database >Mysql Tutorial >MySQL 5.5创建线性Hash分区表,并将表文件分布到不同的物理磁盘上_MySQL

MySQL 5.5创建线性Hash分区表,并将表文件分布到不同的物理磁盘上_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:36:451143browse

bitsCN.com

MySQL 5.5创建线性Hash分区表,并将表文件分布到不同的物理磁盘上

 

要合并不同服务器上的数据,考虑到以后会不断添加游戏区组服务器,所以使用mysql5.5的LINEAR HASH分区,当添加的区组超过hash分区后再添加分区,停机维护时再将新添加的分区表文件分布到其他物理分区上去.

下面是建表SQL

 

DROP TABLE IF EXISTS gyyx_middle.`wd_char_info`;

tudou@Gyyx

CREATE TABLE gyyx_middle.`wd_char_info` (

  `dist` int(11) NOT NULL DEFAULT '0',

  `account` varchar(32) NOT NULL DEFAULT '玩家帐户',

  `name` varchar(32) NOT NULL DEFAULT '',

    `create_date`   INT(11) NOT NULL DEFAULT '0',

  `create_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

  `first_login_ip` int(11) NOT NULL DEFAULT 0,

  `gender` tinyint(11) NOT NULL DEFAULT '0',

    `last_login_date` INT(11) NOT NULL DEFAULT '0',

  `last_login_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

  `last_login_ip` int(11) NOT NULL DEFAULT 0,

  `glory` int(11) NOT NULL DEFAULT '0',

  `level` mediumint(11) NOT NULL DEFAULT '0',

  `tao` int(11) NOT NULL DEFAULT '0',

  `cash` int(11) NOT NULL DEFAULT '0',

  `nice` int(11) NOT NULL DEFAULT '0',

  `reputation` int(11) NOT NULL DEFAULT '0'

) ENGINE=MyISAM DEFAULT CHARSET=latin1

PARTITION BY LINEAR HASH(`dist`)

PARTITIONS 500;

 

将分区文件为偶数的表文件分布到另一个物理分区上    

 

#!/bin/sh

FILEDIR="/data/mysql5_5_20/data/gyyx_middle/"

MVDIR="/data1/mysql5_5_20/data/gyyx_middle/"

for i in `seq 0 249`

do

i=$[i*2]

mv ${FILEDIR}"wd_char_info#P#p"${i}".MYI" ${MVDIR}"wd_char_info#P#p"${i}".MYI"

mv ${FILEDIR}"wd_char_info#P#p"${i}".MYD" ${MVDIR}"wd_char_info#P#p"${i}".MYD"

done

 

在原目录下建立软链接

 

#!/bin/sh

FILEDIR="/data1/mysql5_5_20/data/gyyx_middle/"

LNDIR="/data/mysql5_5_20/data/gyyx_middle/"

FILELIST=`ls $FILEDIR`

for FILENAME in $FILELIST

do

ln -s ${FILEDIR}${FILENAME} ${LNDIR}${FILENAME}

done

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn