Pete's information junkyard

Limiteren van resources MySql

Webhosting is vaak een lastig punt, als het gaat om het limiteren van de resources die een gebruiker kan gebruiken. Als de gebruiker een onjuist geconfigureerde database maakt, of slechte queries, kunnen zij acties de andere gebruikers in de weg zitten doordat de server te druk wordt. Erg vervelend natuurlijk. MySql heeft schijnbaar wat functionaliteit ingebouwt hiervoor.

Op een forum vond ik deze tekst:

Lightwave 04-15-2005, 10:01 PM
Originally posted by John[H4Y]
http://dev.mysql.com/doc/mysql/en/user-resources.html

It looks like versions of MySQL 4.02 may introduce more controls on a per-account basis. I have never experimented with this, but looks like it is worth a shot.

With 4.0.2+ You can do per user restrictions

As a prerequisite for using this feature, the user table in the mysql database must contain the resource-related columns. Resource limits are stored in the max_questions, max_updates, max_connections, and max_user_connections columns. If your user table doesn't have these columns, it must be upgraded; see Section 2.10.7, “Upgrading the Grant Tables”. http://dev.mysql.com/doc/mysql/en/upgrading-grant-tables.html

To set resource limits with a GRANT statement, use a WITH clause that names each resource to be limited and a per-hour count indicating the limit value. For example, to create a new account that can access the customer database, but only in a limited fashion, issue this statement:

mysql> GRANT ALL ON customer.* TO 'francis'@'localhost'
-> IDENTIFIED BY 'frank'
-> WITH MAX_QUERIES_PER_HOUR 20
-> MAX_UPDATES_PER_HOUR 10
-> MAX_CONNECTIONS_PER_HOUR 5
-> MAX_USER_CONNECTIONS 2;

What you want is something like:

mysql> GRANT USAGE ON *.* TO 'francis'@'localhost'
-> WITH MAX_USER_CONNECTIONS 20;

assuming francois@localhost is the user you wish to restrict.

Dit heb ik natuurlijk even geprobeerd, en dat werkt! Weer wat geleerd. Voor meer informatie is er natuurlijk wel wat te vinden op de MySql website: http://dev.mysql.com/doc/refman/5.5/en/user-resources.html

Tags: MySql
Created on 25-10-2011






stopsoftwarepatents.eu petition banner