MySQL automatically generated large amounts of data

To learn verify high-performance MySQL, automatically generated large amounts of data to do the test. Content from the network.

Create random number generation
DELIMITER $$
the CREATE DEFINER root` = `@`% `` random_num` the FUNCTION () the RETURNS int (. 5)
the BEGIN 
 the DECLARE the DEFAULT the INT 0 I; 
 the SET I = the FLOOR (100 + the RAND () * 10); 
the RETURN I; 
 the END $$
DELIMITER;

生成随机字符串
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `random_string`(n INT) RETURNS varchar(255) CHARSET latin1
BEGIN
 DECLARE chars_str VARCHAR(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ';
 DECLARE return_str VARCHAR(255) DEFAULT '';
 DECLARE i INT DEFAULT 0;
 WHILE i < n DO
 SET return_str =CONCAT(return_str,SUBSTRING(chars_str,FLOOR(1+RAND()*52),1));
 SET i = i + 1;
 END WHILE;
 RETURN return_str;
END$$
DELIMITER ;

Generating a random number, return data type varchar compositions, for example, phone number
DELIMITER $$
the CREATE DEFINER root` = `@`% `` random_string_phone` the FUNCTION (n-the INT) the RETURNS varchar (255) the CHARSET latin1
the BEGIN
 the DECLARE chars_str VARCHAR (100) the DEFAULT ' 1234567890 ';
 the DECLARE return_str VARCHAR (255) the DEFAULT' ';
 the DECLARE I the INT the DEFAULT 0;
 the WHILE I <n-the DO
 the SET return_str = CONCAT (return_str, the SUBSTRING (chars_str, the FLOOR (. 1 + the RAND () * 10),. 1));
 I = I +. 1 the SET;
 the END the WHILE;
 the RETURN return_str;
the END $$
DELIMITER;

Create a user table myisam engine
the CREATE TABLE `sys_user_myisam` (
  ` user_id` bigint (100) the NOT NULL AUTO_INCREMENT,
  `username` VARCHAR (100) NULL the DEFAULT the COMMENT 'user name',
  ` password` VARCHAR (100) NULL the DEFAULT the COMMENT 'password' ,
  `salt` VARCHAR (100) the COMMENT the DEFAULT NULL 'salt',
  ` email` VARCHAR (100) the COMMENT the DEFAULT NULL 'mailbox',
  `mobile` VARCHAR (100) the COMMENT the DEFAULT NULL 'phone number',
  ` status` int (. 1 ) DEFAULT '1' COMMENT 'status 0: disabled 1: normal',
  a PRIMARY KEY ( `user_id`)
) ENGINE = MyISAM the AUTO_INCREMENT the DEFAULT the CHARSET = 1000001 = UTF8 the COMMENT = 'user MyISAM';

创建存储过程生成数据
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `insert_sys_user_myisam`(IN START INT(10),IN max_num INT(10))
BEGIN 
DECLARE i INT DEFAULT 0; 
 SET autocommit = 0;   
 REPEAT 
 SET i = i + 1; 
 INSERT INTO sys_user_myisam (user_id,username,password,salt,email,mobile,status) VALUES (START+i,random_string(10),random_string(6),random_string(10),random_string(20),random_string_phone(12),1); 
 UNTIL i = max_num 
 END REPEAT; 
 COMMIT; 
 END$$
DELIMITER ;

创建表innodb引擎
create table sys_user_innodb ENGINE=MyISAM AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8 as select * from sys_user_myisam;

Guess you like

Origin www.linuxidc.com/Linux/2020-03/162664.htm