怎样在mysql中插入大量的数据

发布网友

我来回答

2个回答

懂视网

> create table bigdata (id int,name char(2)); 创建存储过程: mysql> delimiter // mysql> create procedure rand_data(in num int) -> begin -> declare str char(62) default ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567‘; --总共62个字符。 -> declare str2 char(2); -> declare i int default 0; -> while i<num do -> set str2=concat(substring(str,1+floor(rand()*61),1),substring(str,1+floor(rand()*61),1)); -> set i=i+1; -> insert into bigdata values (floor(rand()*num),str2); -> end while; -> end; -> // Query OK, 0 rows affected (0.01 sec) mysql> delimiter ; 插入一百万条数据:

mysql> call rand_data(1000000);

  Query OK, 1 row affected (1 hour 11 min 34.95 sec)

 

 

mysql> select * from bigdata limit 300,10;
+--------+------+
| id | name |
+--------+------+
| 230085 | WR |
| 184410 | 7n |
| 540545 | nN |
| 2578 | Tf |
| 571507 | at |
| 577023 | 0M |
| 731172 | 7h |
| 914168 | ph |
| 391848 | h6 |
| 665301 | dj |
+--------+------+
10 rows in set (0.00 sec)

 

插入数据成功。

 

Mysql大量插入随机数据方法--存储过程

标签:

热心网友

方法一,从已有大数据表中检索大量数据插入到目标表里;

方法二,编写存储过程,利用循环向数据表中插入大量的固定或有规律变化或随机变化的虚拟数据;

方法三,通过应用程序端编程向目标表插入大量的数据,手法与方法二类似。追答方法一补充,还可以反复检索某表数据插入到目标表中。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com