如何在 MySQL 中创建一个包含多个随机值列的大 table?

How to create a big table with several columns with random values in MySQL?

我需要为 MySQL 测试不同的 GUI 工具。为此,我需要包含大表的数据库。我使用存储过程进行了尝试,但问题是不同字段中的值在所有行中都是相同的。我需要的是这些值应该是随机的。有没有办法做到这一点?

提前致谢!

我认为更好的方法是编写一个 java 应用程序。创建一些循环来生成大量字段和数据非常容易。

好吧,有许多 MySQL 内置数学函数可用于生成随机数据。例如,在您的存储过程中,您可以添加这些 SQL 语句来生成随机数据,然后将它们插入到 table 中它们各自的字段中。 MySQL CONV() 将数字从一个数字基数系统转换为另一个数字基数系统。函数转换后 returns 数字的字符串表示形式。其语法为:CONV(num, from_base, to_base)

select conv(floor(rand() * 99999999999999), 10, 24);

生成 5 个随机字符串并将其插入学生 table 的示例存储过程看起来有点像这样:

delimiter $$  
  create procedure randomizer()
    begin
      declare i int Default 0 ;
      declare random char(20) ;
      myloop: loop
      set random=conv(floor(rand() * 99999999999999), 10, 24) ;
      insert into `student` (`id`, `name`) VALUES (i+1,random) ;
      set i=i+1;
      if i=5 then
        leave myloop;
    end if;
    end loop myloop;
  end $$
  delimiter ;

希望对您有所帮助。