mysql 带参数的存储过程插入百万条记录示例
2018-01-16 本文已影响0人
shadow雨轩
# 创建表
DROP TABLE IF EXISTS t_user;
CREATE TABLE t_user(
id varchar(36),
COUNT int,
comm varchar(10)
)ENGINE=INNODB,CHARSET=utf8;
#定义存储过程
DROP PROCEDURE IF EXISTS test_insert;
DELIMITER //
CREATE PROCEDURE test_insert(cnt int)
BEGIN
DECLARE i int DEFAULT 0;
START TRANSACTION;
WHILE i
DO
INSERT INTO t_user(id,COUNT,comm) VALUES(UUID(),i,'测试数据');
set i=i+1;
end WHILE;
COMMIT;
end //
DELIMITER;
CALL test_insert(1000000);
SELECT * FROM t_user tu WHERE tu.COUNT=999999;