“最大问题数”通过 PHP 运行 MySQL 查询时不遵守限制
我在 Windows Server 2008 平台上使用 MySQL Community Server 5.5 和 PHP 5.3.3。 我已经设置了每个用户的资源限制,特别是与数据库用户在一小时内运行的查询相关的限制。我读过这份文件,它非常有趣,但总是对我不起作用。
http://dev.mysql.com/doc/refman/5.5 /en/user-resources.html
当我通过 mysql 命令行工具 (mysql.exe) 运行查询时,限制正常工作,如果每小时的查询限制为 7,在一小时内进行 7 次查询后,我收到错误:
错误 1226 (42000):用户“user”已 超出了“max_questions”资源 (当前值:7)
以上是所需的行为。
当我通过 PHP 运行查询时(我用来连接到数据库的用户与上面相同),查询限制不起作用:通过 php 的同一用户可以运行它想要的所有查询,而没有任何限制。如果我回到 mysql 命令行,上面的计数器似乎被重置了(即使一小时还没有过去):我也可以在一小时内运行 7 个查询。 我认为这不是想要的行为。看来 PHP 重置了计数器并且没有触发查询限制。
PS:“用户”仅拥有SELECT,INSERT,UPDATE,DELETE
权限,并且在PHP代码中没有任何SQL代码作为用户“用户”的FLUSH USER_RESOURCES
' 无法运行(因为 RELOAD
权限未分配给用户)
提前致谢
I'm using MySQL Community Server 5.5 with PHP 5.3.3 on a Windows Server 2008 platform.
I have set up per user resources limits, particularly a limit related to the queries run by a DB user within one hour. I have read this document and it is very interesting but always it doesn't work for me.
http://dev.mysql.com/doc/refman/5.5/en/user-resources.html
When I run a query via mysql command line tool (mysql.exe) the limit works properly and if the queries limit per hour was 7, after 7 queries within one hour I receive the error:
ERROR 1226 (42000): User 'user' has
exceeded the 'max_questions' resource
(current value: 7)
This above is the wanted behavior.
When I run a query via PHP (The user I have used to connect to the DB is the same above), the queries limit doesn't work: the same user via php can run all the queries it wants and without any limit. And if I come back on the mysql command line above the counter seems to be reset (even if the hour hasn't elapsed) : I can run 7 queries within an hour too.
I think this isn't the wanted behaviour. It seems that PHP resets the counter and doesn't trigger the queries limit.
PS: The 'user' owns only SELECT,INSERT,UPDATE,DELETE
privileges and in the PHP code there isn't any SQL code as FLUSH USER_RESOURCES
that the user 'user' couldn't have run (because RELOAD
privilege isn't assigned to the user)
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查这个提示,
你的 mysql 中有多少个同名的用户..(不仅要记住名称,还要记住 mysql 中指定了允许连接该用户的主机)。 **非常重要。
用户@%
[电子邮件受保护]
用户@localhost
[email protected]
每一个都不相同,如果您有任何您喜欢使用的限制规则,那么您必须将限制分配给 user@无论您想要限制的地方。 (所有这些,如果您遇到问题**认为是您的情况)。
建议:为 WEB PHP 创建一个特定用户(必须创建一个 user@host),而不是使用可能分配了多个 users@hosts 的通用用户。
像 phpuser@'localhost' 通常就足够了。
Check this tip,
how many users do you have in your mysql with the same name..(remember not only the name but the host where is permited to connect the user is specified in mysql ). **VERY IMPORTANT.
user@%
[email protected]
user@localhost
[email protected]
each one of them are not the same, if you have any limit rule do you like to use, so, you must assign limitations to the user@wherever you want the limintation. (all of them, if you have problems **think is your case).
Recomendation: create a specific user for WEB PHP (only one user@host must be created) , instead using a generic user with may have several users@hosts assigned.
like phpuser@'localhost' typically is enough.
我认为你犯了一个小错误,
请检查 mysql_connect 函数中的主机到 php 中。
如果您的主机是 IP 地址,那么您需要将资源限制分配给 username@yourip 或 username@%
如果您通过命令行运行,那么您是从 username@localhost 登录,并且您已将限制分配给同一用户。
请尝试我的上述技巧,如果您仍然遇到问题,请告诉我?
快乐编码....
I think you are doing little mistake,
Please check for the host in your mysql_connect function into php.
if your host is IP address then you need to assign the resource limit to username@yourip or username@%
If you are running through the command line then you are login from username@localhost and you have assign the limit to the same user.
Please try my above tricks and let me know if you are having problem still ?
Happy coding....
我已经(部分)解决了这个问题。
仅当包含 MAX_QUERIES_PER_HOUR 组件的查询还包含以下不同于 0 的元素之一时,才会出现此问题:
例如,以下授予查询不会导致与 PHP 中的查询限制成就相关的错误消息:
相反,以下授予可以正常工作MySQL 正确应用了这些限制。
简而言之,当查询设置查询限制包括 MAX_CONNECTIONS_PER_HOUR 和 MAX_USER_CONNECTIONS 不同于 0 的组件之一时,与 MAX_QUERIES_PER_HOUR 和 MAX_UPDATES_PER_HOUR 相关的限制将被忽略:我的 PHP 页面可以执行它们想要的所有查询。否则,限制将被理解并且消息
当查询限制实现事件发生时,会正确显示
。 正如我上面所说,当我使用 mysql 命令行工具时,不会出现问题。仅当通过 PHP 页面运行查询时才会发生。
I have solved (partially) the problem.
The problem occurs only when the query including the MAX_QUERIES_PER_HOUR component includes also one of the following elements different from 0:
e.g. the following grant query won't ever cause the error message related to the queries limit achievement in PHP:
Instead the following grant works correctly and MySQL applies the limits correctly.
In short, when the query setting queries limit includes one of the components, MAX_CONNECTIONS_PER_HOUR and MAX_USER_CONNECTIONS different from 0, the limits related to the MAX_QUERIES_PER_HOUR and MAX_UPDATES_PER_HOUR are ignored: my PHP pages can perform all the queries they want. Otherwise the limit is understood and the message
correctly is showed when the queries limit achievement event occurs.
As I said above the problem doesn't occurs when I use the mysql command line tool. It occurs only when queries are run through PHP pages.