如何在 MySql 中限制查询或确定查询优先级
MySQL 中是否有办法对查询进行优先级排序或限制?
我是服务器上的 DBA,我发现大量未优化的查询进入服务器,它们只会破坏 CPU。我正在考虑限制某些以不良方式访问数据库的用户。
澄清:
我意识到MySQL内置了限制查询、连接数量等的设施。但这些并不是真正的问题,而是用户千载难逢地会发送未经优化的查询,我需要超时或类似的事情。
Is there anyway to prioritize or throttle a query at all in MySQL?
I'm a DBA on a server that sees a lot of unoptimized queries come into the server and they just destroy the CPU. I'm looking at throttling certain users that hit on the database in poor fashion.
Clarification:
I realize that MySQL has facilities built in to limit number of queries, connections, etc. But those aren't really the issue, it's that once in a blue moon a user will send an unoptimized query, and I'd need to time it out or something similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://dev.mysql.com/doc/refman/4.1 /en/user-resources.html
从 MySQL 4.0.2 开始,您可以限制单个帐户对以下服务器资源的访问:
帐户每小时可以发出的查询数量
帐户更新的数量每小时可以发出
帐户每小时可以连接到服务器的次数
其他信息 -
MySQL 没有查询超时值,也没有任何其他内置方法来限制单个查询。然而,编写一个终止长时间运行的查询的脚本是非常简单的。您甚至可以捕获用户和查询,以便稍后击败有问题的用户/程序员。
这里是一个使用 PERL 的示例。
http://dev.mysql.com/doc/refman/4.1/en/user-resources.html
Starting from MySQL 4.0.2, you can limit access to the following server resources for individual accounts:
The number of queries that an account can issue per hour
The number of updates that an account can issue per hour
The number of times an account can connect to the server per hour
Additional Info -
MySQL does not have a query timeout value, or any other built-in way to throttle an individual query. However, it is pretty trivial to write a script that will kill long-running queries. You could even capture the user and query so that you can beat the offending user/programmer later.
Here is an example of one using PERL.
我知道 phpMyAdmin 有一个区域用于每小时最大查询数、每小时最大更新数、每小时最大连接数和每个用户的最大用户连接数。除了 phpMyAdmin 之外,可能还有其他方法来设置这些值
I know that phpMyAdmin has an area for Max # of Queries per hour, Max # of Updates per hour, Max # of Connections per hour, and Max # of User Connections per user. There are probably other ways to set these values other than phpMyAdmin