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

來源:互聯網
上載者:User

標籤:

在mysql資料庫中製作千萬級測試表前言:最近準備深入的學一下mysql,包括各種引擎的特性、效能最佳化、分表分庫等。為了方便測試效能、分表等工作,就需要先建立一張比較大的資料表。我這裡準備先建一張千萬記錄使用者表。步驟:1 建立資料表(MYISAM方式儲存插入速度比innodb方式快很多) 資料表描述資料量:1千萬欄位類型:id :編號uname:使用者名稱ucreatetime: 建立時間age:年齡CREATE TABLE usertb(   id serial,    uname  varchar(20) ,   ucreatetime  datetime  ,   age  int(11))   ENGINE=MYISAM DEFAULT 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秒的時間

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.