文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

MySQL大数据存储(一)  


1:根据用户的信息进行算法进行分表入库。
function get_hash_table($table,$userid) {  
    $str = crc32($userid);  
    if($str<0) {  
        $hash = "0".substr(abs($str), 0, 1);  
    } else {  
        $hash = substr($str, 0, 2);  
    }
    return $table."_".$hash;  
}  


2:利用MySQL的Merge引擎
CREATE TABLE `test_merge` (
  `ID` int(5) NOT NULL,
  `VALUE` varchar(100) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=

(`test_merge_1`,`test_merge_2`);

CREATE TABLE `test_merge_1` (
  `ID` int(5) NOT NULL,
  `VALUE` varchar(100) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `test_merge_2` (
  `ID` int(5) NOT NULL,
  `VALUE` varchar(100) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO TEST_MERGE_1(ID,VALUE) VALUES(1,'phper.yang');
INSERT INTO TEST_MERGE_2(ID,VALUE) VALUES(1,'houhuiyang');

直接select * from test_merge;可以看到分别在1 2表中