create-500k-random-rows-table.sql 641 B

123456789101112131415161718192021222324252627282930
  1. -- from http://sixarm.com/about/mysql-create-random-data-text-strings.html
  2. drop table if exists foos;
  3. drop procedure if exists randomizer;
  4. CREATE TABLE foos (
  5. id int(11) NOT NULL AUTO_INCREMENT,
  6. name char(20),
  7. PRIMARY KEY (id)
  8. );
  9. delimiter $$
  10. create procedure randomizer()
  11. begin
  12. declare i int Default 0 ;
  13. declare random char(20);
  14. myloop: loop
  15. set random=conv(floor(rand() * 99999999999999), 20, 36) ;
  16. insert into `foos` (`id`, `name`) VALUES (i+1,random) ;
  17. set i=i+1;
  18. if i=500000 then
  19. leave myloop;
  20. end if;
  21. end loop myloop;
  22. end $$
  23. delimiter ;
  24. call randomizer;