一、生成测试数据
(1)首先,有表如下
create table app_user(
`id` bigint(20) not null auto_increment comment '用户id',
name varchar(50) not null comment '用户名',
email varchar(50) comment '邮箱',
phone varchar(20) comment '手机号',
gender tinyint(4) comment '性别(0:女,1:男)',
password varchar(100) comment '密码',
age tinyint(4) comment '年龄',
create_time datetime default current_timestamp,
update_time timestamp default current_timestamp,
PRIMARY KEY(`id`)
);
select * from app_user;
(2)插入一条随机数据
INSERT INTO app_user(`name`,`email`,`phone`,`gender`,`password`,`age`)
VALUES (CONCAT('用户1'),
'[email protected]',
CONCAT('18',FLOOR(RAND()*(999999999-100000000)+100000000)),
FLOOR(RAND()*2),
UUID(),
FLOOR(RAND()*70));
(3)使用SQL编程创建100万条数据
DELIMITER $$
CREATE FUNCTION mock_data()
RETURNS INT
BEGIN
DECLARE num INT DEFAULT 1000000;
DECLARE i INT DEFAULT 0;
WHILE i<num DO
-- 插入语句
INSERT INTO app_user(`name`,`email`,`phone`,`gender`,`password`,`age`)
VALUES (CONCAT('用户',i),'[email protected]',
CONCAT('18',FLOOR(RAND()*(999999999-100000000)+100000000)),
FLOOR(RAND()*2),UUID(),FLOOR(RAND()*70));
SET i = i+1;
END WHILE;
RETURN i;
END;
select mock_data();
二、标题
三、标题
— 业精于勤荒于嬉,行成于思毁于随 —
标签:comment,RAND,场景,varchar,FLOOR,INT,timestamp,05,MySQL From: https://www.cnblogs.com/houhuilinblogs/p/18216026