在mysql里执行select 1 from (select count(*),concat(floor(rand(0)*2),(select table_name from information_schema.tables where table_schema='mysql' limit 0,1))a from information_schema.tables group by a)b;这句话,为什么会出错,错误信息是:ERROR 1062 (23000): Duplicate entry '1columns_priv' for key 1,到网上查了下Duplicate entry,貌似是主键重复还是什么的,但还是不太懂,有人能解释下吗?先谢谢了。

解决方案 »

  1.   

    看来是rand的问题  不过不懂是什么原理
      

  2.   

    我觉得rand()函数是没有什么问题的
      

  3.   


    我的mysql是5.0.51b-community-nt-log版本的
      

  4.   


    我看了下,没有什么问题啊。我重新安装的mysql执行这个语句也会出错的
      

  5.   

    不知道楼主的sql语句想做什么,目的是什么,把最后的a换成table_name就好了,还是说楼的问的问题的重点只是在主键重复这个问题上?
      

  6.   

    楼主的
    SQL的关键错在最后一个from information_schema.tables, 它会枚举所有的行。要以尝试下边这个:
    select 1 from 
        (
    select count(*), (concat(floor(rand(0)*2),
    ( select table_name from information_schema.tables where table_schema='mysql' limit 0,1)
    ) ) as a
    from (select 0) c group by a
    ) b
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.00 sec)
      

  7.   

    其实这是一个用来sql注射在显错模式下的语句,但是我不明白为什么这样能够爆出数据来,所以拿到这里来问了