Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

On the method of automatically generating a large amount of data by mysql

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What the editor shares today is the method of automatically generating a large amount of data from mysql. Maybe you are no stranger to mysql, or you have never known mysql. But don't worry, today the editor will use the simplest description to explain how mysql automatically generates a large amount of data.

Mysql automatically generates a large amount of data

In order to learn to verify high-performance mysql, a large amount of data is automatically generated for testing. The content comes from the Internet.

Create random number generation

DELIMITER $$CREATE DEFINER= `root` @ `% `FUNCTION `root` () RETURNS int (5) BEGIN DECLARE i INT DEFAULT 0; SET I = FLOOR (100+RAND () * 10); RETURN I; END$$DELIMITER

Generate random strings

DELIMITER $$CREATE DEFINER= `root` @ `% `FUNCTION `root` (n INT) RETURNS varchar CHARSET latin1BEGIN DECLARE chars_str VARCHAR; 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

Generate random numbers and return varchar type data combinations, such as mobile phone numbers

DELIMITER $$CREATE DEFINER= `root` @ `% `FUNCTION `root` (n INT) RETURNS varchar CHARSET latin1BEGIN DECLARE chars_str VARCHAR DEFAULT '1234567890; DECLARE return_str VARCHAR DEFAULT'; DECLARE i INT DEFAULT 0; WHILE I < n DO SET return_str = CONCAT (return_str,SUBSTRING (chars_str,FLOOR (1+RAND () * 10), 1); SET I = I + 1; END WHILE; RETURN return_str;END$$DELIMITER

Create a user table myisam engine

CREATE TABLE `sys_user_ myisam` (`username` bigint) NOT NULL AUTO_INCREMENT, `username`DEFAULT NULL COMMENT 'username', `password` varchar 'DEFAULT NULL COMMENT' password', `salt`varchar 'DEFAULT NULL COMMENT' salt', `email`varchar 'DEFAULT NULL COMMENT' mailbox', `mobile`varchar 'DEFAULT NULL COMMENT' mobile phone number', `status`int (1) DEFAULT'1' COMMENT 'status 0: disable 1: normal' PRIMARY KEY (`user_ id`) ENGINE=MyISAM AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8 COMMENT=' system user MyISAM'

Create stored procedures to generate data

DELIMITER $$CREATE DEFINER= `root` @ `% `PROCEDURE `root` (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

Create a table innodb engine

Create table sys_user_innodb ENGINE=MyISAM AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8 as select * from sys_user_myisam

The above is the above for the server Windows to do a brief introduction, of course, the detailed use of the above differences have to be used by everyone to understand. If you want to know more, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report