MySQL快速生成100万条数据
2018-07-19 本文已影响113人
知道越多不知道越多
生成数据的思路:
mysql将数据插入内存表的速度很快,所以我们先将数据插入到内存表中,然后再将内存表中的数据insert到普通表中。
创建一个普通表,创建一个对应的内存表:


创建一个存储过程,用于生产100万条数据

执行sql:CALL add_memory_data(1000000); 插入100万条数据
插入的速度很快,一分钟左右就执行完毕
可能会遇到错误:The table 'memory_t' is full
这个问题我们通过修改my.ini配置文件解决:
在【mysqld】下添加一下两句
tmp_table_size=256M
max_heap_table_size=256M
然后重启mysql即可
执行完毕后memory_t表里有100万条数据
然后执行sql:insert into general select * from memory_t;
将数据插入到general 表中
总结:mysql操作内存表真的很快