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
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.