dragon87836215 2011-01-11 08:05
浏览 65
已采纳

如何强制MySQL返回有限的行?

I would like to limit the results from mysql query submitted by users. Currently I am just parsing query string by PHP then appending LIMIT in the end. For more complex queries with many nested selects/joins the things are becoming complex and less predictable. Are there common way to force mysql to return only limited results even if user has asking for full set?

Thanks
Arman

  • 写回答

1条回答 默认 最新

  • duandou2763 2011-01-11 08:14
    关注

    You are asking for some server configuration settings to limit the maximum number of rows returned by all queries. That is, select * from mytable will return maximum x number (x is set in global server configuration) or rows even there are many more rows in the table.

    Unfortunately, this is not possible in standard distributions of MySQL. You can set limits on maximum queries per hour, even what operations a user can do in server. But, limit of number of rows in query result cannot be set globally.

    However, you can get the MySQL community edition source code and add a configuration for global query result limit. Also, if you are using some kind of connector to connect to MySQL (for example, if you are connecting to MySQL from .NET), you can leave the server as is but modify the connector code and add your desired limiting configuration option there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图