久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      mysql如何實(shí)現(xiàn)循環(huán)插入千萬級(jí)數(shù)據(jù)

      mysql如何實(shí)現(xiàn)循環(huán)插入千萬級(jí)數(shù)據(jù)

      mysql如何實(shí)現(xiàn)循環(huán)插入千萬級(jí)數(shù)據(jù)?

      1.建表:

      CREATE TABLE `mysql_genarate` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `uuid` varchar(50) DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5990001 DEFAULT CHARSET=utf8

      2.創(chuàng)建一條條循環(huán)插入的存儲(chǔ)過程

      create procedure test_two1()      begin         declare i int default 0;       while i < 3000 do             INSERT into mysql_genarate(uuid) VALUES(UUID());            set i = i + 1;         end while;     end #

      使用 call test_two1(); 測試,3000條數(shù)據(jù)耗時(shí)74秒,如果是千萬級(jí)數(shù)據(jù),這個(gè)速度將無法忍受。

      所以我在網(wǎng)上找了一下優(yōu)化的方法,發(fā)現(xiàn)可以拼接批量插入的sql語句,速度提升很多;

      3.優(yōu)化后的存儲(chǔ)過程

      CREATE PROCEDURE insertPro(in sum INT)BEGINDECLARE count INT DEFAULT 0;DECLARE i INT DEFAULT 0; set @exesql = concat("insert into mysql_genarate(uuid) values"); set @exedata = ""; set count=0; set i=0;while count<sum do      set @exedata = concat(@exedata, ",(UUID())");     set count=count+1;     set i=i+1;    if i%1000=0     then          set @exedata = SUBSTRING(@exedata, 2);         set @exesql = concat("insert into mysql_genarate(uuid) values ", @exedata);         prepare stmt from @exesql;         execute stmt;        DEALLOCATE prepare stmt;         set @exedata = "";    end if;end while;if length(@exedata)>0 then      set @exedata = SUBSTRING(@exedata, 2);     set @exesql = concat("insert into mysql_genarate(uuid) values ", @exedata);     prepare stmt from @exesql;     execute stmt;    DEALLOCATE prepare stmt;end if;end;

      調(diào)用 call insertPro(3000) ,耗時(shí)零點(diǎn)幾秒,這個(gè)速度可以接受。

      接著調(diào)用 call insertPro(30000000) ;測試3000萬條數(shù)據(jù)插入,結(jié)果耗時(shí)1824.203s(30分鐘)。個(gè)人電腦這個(gè)速度可以了。

      另外,采用java多線程同時(shí)拼接sql,每10000條提交一次的方式,在8個(gè)線程同時(shí)運(yùn)行的情況下,3000萬條數(shù)據(jù)插入耗時(shí)336s,1億條數(shù)據(jù)插入耗時(shí)1087s。

      相關(guān)參考:MySQL教程


      贊(0)
      分享到: 更多 (0)
      ?
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)