#create testtable
CREATE TABLE `testtable` ( `id` int(11) NOT NULL, `createdTime` datetime DEFAULT NULL, `login` text, `testid` varchar(63) DEFAULT NULL, PRIMARY KEY (`id`) ) PARTITION BY RANGE (TO_DAYS(createdTime)) ( PARTITION p01 VALUES LESS THAN (TO_DAYS(‘2013-07-01 00:00:00‘)), PARTITION p02 VALUES LESS THAN (TO_DAYS(‘2013-08-01 00:00:00‘)), PARTITION p03 VALUES LESS THAN (TO_DAYS(‘2013-09-01 00:00:00‘)), PARTITION p04 VALUES LESS THAN (TO_DAYS(‘2013-10-01 00:00:00‘)), PARTITION p05 VALUES LESS THAN (TO_DAYS(‘2013-11-01 00:00:00‘)), PARTITION p06 VALUES LESS THAN (TO_DAYS(‘2013-12-01 00:00:00‘)) );
##存储过程
drop procedure generator; delimiter // CREATE PROCEDURE generator ( t_count INT(10) ) BEGIN DECLARE v_sql varchar(1000); DECLARE v_count INT; SET v_count = 0; loop_label:LOOP SET v_count = v_count + 1; IF v_count%100000=0 THEN select v_count; END IF; IF v_count>t_count THEN LEAVE loop_label; END IF; SET v_sql = CONCAT(‘INSERT INTO testtable VALUES (‘,v_count,‘,\‘FAILED\‘,v_count,‘\‘)‘); SET @sql = v_sql; PREPARE sl FROM @sql; EXECUTE sl; DEALLOCATE PREPARE sl; END LOOP; END; // delimiter ;
##生成测试数据
set @t_count=10000000; call generator(@t_count);
原文地址:http://davidsolomon.blog.51cto.com/3295360/1611809