Create tens of millions of test tables and mysql database test tables in the mysql database

Source: Internet
Author: User
Tags database sharding

Create tens of millions of test tables and mysql database test tables in the mysql database
Preface:

I have recently prepared to learn more about mysql, including the features, performance optimization, and database sharding of various engines. To facilitate testing performance and table sharding, you must first create a large data table. I am going to create a user table with 10 million records first.


Steps: 1. Create a data table (MYISAM stores and inserts data much faster than innodb)

Data table description

Data volume: 10 million
Field Type:
Id: No.
Uname: User Name
Ucreatetime: Creation Time
Age: 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. Create a stored procedure for data insertion

Delimiter $ set autocommit = 0 $ create procedure test1 () begindeclare v_cnt decimal (10) default 0; dd: loop insert into usertb values (null, 'user 1 ', '2017-01-01 00:00:00 ', 20), (null, 'user 2', '2017-01-01 00:00:00', 20), (null, 'user 3 ', '2017-01-01 00:00:00 ', 20), (null, 'user 4', '2017-01-01 00:00:00', 20), (null, 'user 5 ', '2017-01-01 00:00:00 ', 20), (null, 'user 6', '2017-01-01 00:00:00', 20), (null, 'user 7 ', '2017-01-01 00:00:00 ', 20), (null, 'user 8', '2017-01-01 00:00:00', 20), (null, 'user 9 ', '2017-01-01 00:00:00 ', 20), (null, 'user 0', '2017-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. Execute the Stored Procedure

call test1;

Time consumed: it only takes 95 seconds to execute an i5 notebook.

4. Modify engineer as needed (non-essential steps. If conversion is not required, no operation is required)

alter table usertb engine=innodb;
Time consumed: it takes only 200 seconds to execute an i5 notebook.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.