zoukankan      html  css  js  c++  java
  • mysql使用存储过程快速插入百万条数据

    下面就让我们开始创建表插入数据吧

    --创建MyISAM模式表方便批量跑数据

    CREATE TABLE `my_tables` (
    `id` bigint(32) NOT NULL AUTO_INCREMENT,
    `name` varchar(32) DEFAULT NULL,
    `age` int(32) DEFAULT NULL,
    `time` varchar(32) DEFAULT NULL,
    `pwd` varchar(32) DEFAULT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;


    --创建存储过程

    DROP PROCEDURE IF EXISTS my_insert;
    CREATE PROCEDURE my_insert()
    BEGIN
    DECLARE n int DEFAULT 1;
    loopname:LOOP
    INSERT INTO `my_tables`(`name`,`age`,`time`,`pwd`) VALUES ('张三', 18, '0:0:0:0:0:0:0:1', '369');
    SET n=n+1;
    IF n=1000000 THEN
    LEAVE loopname;
    END IF;
    END LOOP loopname;
    END;

    --执行存储过程


    CALL my_insert();

    --数据插入成功后修改表模式InnoDB 时间稍微久点

    alter table `my_tables` engine=InnoDB;

  • 相关阅读:
    正则表达式
    爬虫原理和网页构造
    简单的博客系统之二
    配置编辑器geany
    linux删除多文件
    eNSP交换路由基础
    NTP centOS6.5
    shell脚本之lftp上传
    进度条
    maketrans与translate函数
  • 原文地址:https://www.cnblogs.com/guagua-join-1/p/9849415.html
Copyright © 2011-2022 走看看