CREATE TABLE `app_user` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) DEFAULT ‘‘ COMMENT‘用户昵称‘,
`email` VARCHAR(50) NOT NULL COMMENT‘用户邮箱‘,
`phone` VARCHAR(20) DEFAULT ‘‘ COMMENT‘手机号‘,
`gender` TINYINT(4) UNSIGNED DEFAULT ‘0‘ COMMENT ‘性别(0:男;1:女)‘,
`password` VARCHAR(100) NOT NULL COMMENT ‘密码‘,
`age` TINYINT(4) DEFAULT ‘0‘ COMMENT ‘年龄‘,
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT = ‘app用户表‘
DROP FUNCTION IF EXISTS mock_data;
-- 写函数之前必须要写,标志:$$
DELIMITER $$
CREATE FUNCTION mock_data()
RETURNS INT
DETERMINISTIC
-- 注意returns,否则报错。
BEGIN
DECLARE num INT DEFAULT 1000000;
-- num 作为截止数字,定义为百万,
DECLARE i INT DEFAULT 0;
WHILE i<num DO
INSERT INTO `app_user`(`name`,`email`,`phone`,`gender`,`password`,`age`)VALUES(CONCAT(‘用户‘,i), CONCAT(‘100‘,i,‘@qq.com‘), CONCAT(‘13‘, FLOOR(RAND()*(999999999-100000000)+100000000)),FLOOR(RAND()*2),UUID(), FLOOR(RAND()*100));
SET i = i + 1;
END WHILE;
RETURN i;
END;
SELECT mock_data() -- 执行函数
用sql插入100万条数据