在mysql資料庫中製作千萬級測試表,mysql資料庫測試表

來源:互聯網
上載者:User

在mysql資料庫中製作千萬級測試表,mysql資料庫測試表
前言:

最近準備深入的學一下mysql,包括各種引擎的特性、效能最佳化、分表分庫等。為了方便測試效能、分表等工作,就需要先建立一張比較大的資料表。我這裡準備先建一張千萬記錄使用者表。


步驟: 1 建立資料表(MYISAM方式儲存插入速度比innodb方式快很多)

資料表描述

資料量:1千萬
欄位類型:  
id :編號
uname:使用者名稱
ucreatetime: 建立時間
age:年齡

CREATE TABLE usertb (  id serial,   uname  varchar(20) ,  ucreatetime  datetime  ,  age  int(11)   )  ENGINE=MYISAMDEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci  AUTO_INCREMENT=1  ROW_FORMAT=COMPACT; 

2 建立插入資料存放區過程

delimiter $$SET AUTOCOMMIT = 0$$create  procedure test1() begindeclare v_cnt decimal (10)  default 0 ;dd:loop           insert  into usertb values (null,'使用者1','2010-01-01 00:00:00',20),(null,'使用者2','2010-01-01 00:00:00',20),(null,'使用者3','2010-01-01 00:00:00',20),(null,'使用者4','2010-01-01 00:00:00',20),(null,'使用者5','2011-01-01 00:00:00',20),(null,'使用者6','2011-01-01 00:00:00',20),(null,'使用者7','2011-01-01 00:00:00',20),(null,'使用者8','2012-01-01 00:00:00',20),(null,'使用者9','2012-01-01 00:00:00',20),(null,'使用者0','2012-01-01 00:00:00',20);                  commit;                    set v_cnt = v_cnt+10 ;                           if  v_cnt = 10000000 then leave dd;                          end if;         end loop dd ;end;$$delimiter ;

3 執行預存程序

call test1;

耗時:用i5的筆記本執行也只需要95秒的時間

4 根據需要修改engineer (非必要步驟,如果不需要轉換無需操作)

alter table usertb engine=innodb;
耗時:用i5的筆記本執行也只需要200秒的時間


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.