平時測試,由於我們的測試數據量不夠,不能很好的測試sql性能,故寫了一個sql存儲過程腳本,可以輕鬆寫入100W+數據。
delimiter // —— 與結尾的【end//】共同構成一個結構體,告訴mysql,以下命令是一個整體,否則mysql會遇到【;】就執行
CREATE PROCEDURE insertdata() —— 創建一個名爲insertdata的存儲過程
begin
declare yourid int; —— 聲明 yourid變量爲int型
declare tid int;
declare types int;
declare id int;
set yourid = 270; —— 爲 yourid變量賦值
set tid = 270 ;
set types = FLOOR(1 + RAND() * (4)); —— 爲 types變量賦值,值爲1~4的隨機值
set id = 43200;
while yourid<5270 do ——設定循環條件(雙循環)
set yourid=yourid+1;
while tid <350 do ——設定循環條件
set types = FLOOR(1 + RAND() * (4));
insert into wp_logs VALUES ( id,64,tid,yourid,types,1474360037,1,0,''); ——
執行insert 語句
set tid=tid+1; —— 爲 tid變量賦值
set id=id+1;
END WHILE;
set tid = 270 ;
END WHILE;
end //