Home  >  Article  >  Backend Development  >  [PHP] 如何往 MYSQL 中填入大量随机数据 , 以测试语句性能 ?

[PHP] 如何往 MYSQL 中填入大量随机数据 , 以测试语句性能 ?

WBOY
WBOYOriginal
2016-06-06 20:41:531091browse

自己有一个空的 MYSQL 数据库, 如何往 MYSQL 中填入大量随机数据 , 以测试语句性能 ?

大家集思广益, 能跳过 PHP 直接用 SQL 实现更好.

目标 50万 -- 100万 这个级别左右.

回复内容:

自己有一个空的 MYSQL 数据库, 如何往 MYSQL 中填入大量随机数据 , 以测试语句性能 ?

大家集思广益, 能跳过 PHP 直接用 SQL 实现更好.

目标 50万 -- 100万 这个级别左右.

试试generatedata 这个是开源的, 可以在本地搭建一个站点,生成自己想要的数据。
其他类似的还有很多,参考这个列表:

http://databene.org/databene-benerator/similar-products.html

php 生成一个sql文件 导入~

INSERT INTO `table` ( `field1`, `field2` ) 
VALUES
( 1,1 ),
( 2,2 )
....
( 5000,5000 );

自己偶然间发现了一个纯 SQL 的办法, 嘎嘎!

BENCHMARK(loop_count,expression)

试试存储过程 比PHP要快多了

declare i int default 0;
while i insert into users(value) values(RAND());
set i = i + 1;
end while;
一句SQL不是就搞这了

貌似不行把,之前问过专业dba

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn