mysql分表

详情链接:http://blog.51yip.com/mysql/949.html

分表1:

CREATE TABLE IF NOT EXISTS `user1` (

`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`sex` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

分表2:
CREATE TABLE IF NOT EXISTS `user2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`sex` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)  
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;


总表:

CREATE TABLE IF NOT EXISTS `alluser` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`sex` int(1) NOT NULL DEFAULT '0',
INDEX(id)
) TYPE=MERGE UNION=(user1,user2) INSERT_METHOD=LAST AUTO_INCREMENT=1 ;

如果执行出错,试试:


CREATE TABLE IF NOT EXISTS `alluser` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`sex` int(1) NOT NULL DEFAULT '0',
INDEX(id)
) ENGINE=MyISAM UNION=(user1,user2) INSERT_METHOD=LAST AUTO_INCREMENT=1 ;

你可能感兴趣的:(mysql分表)