mysql建百万数据
https://www.bmabk.com/index.php/post/15010.html
1建表
CREATE TABLE `t_sales` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT '用户名',
`password` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT '密码 MD5存储',
`register_time` timestamp NULL DEFAULT NULL COMMENT '注册时间',
`type` int(1) DEFAULT NULL COMMENT '用户类型 1,2,3,4 随机',
PRIMARY KEY (`id`),
KEY `idx_username` (`username`) USING BTREE
)
2建存储过程
create procedure salesAdd()
begin
declare i int default 1;
set autocommit = 0;
while i <= 8000000 do
insert into t_sales
(`username`,`password`,`register_time`,type) values
(concat("jack",i),MD5(concat("psswe",i)),from_unixtime(unix_timestamp(now()) - floor(rand() * 800000)),floor(1 + rand() * 4));
set i = i + 1;
end while;
set autocommit = 1;
end
3、drop
drop PROCEDURE salesAdd
4、调用存储过程
call salesAdd()