|
今天看到手册,不小心看到了这里,自己做了几个例子。
从MYSQL4.x开始,MYSQL就增加了以每个用户为基础,限制MYSQL服务器的资源利用。 自己查看MYSQL.USER 表就会发现里面最后几个字段:
mysql> select version();+------------------------------------+| version() |+------------------------------------+| 5.1.17-beta-community-nt-debug-log |+------------------------------------+1 row in set (0.00 sec) *************************** 36. row ***************************
Field: max_questions Type: int(11) unsigned Null: NO Key:Default: 0 Extra:*************************** 37. row *************************** Field: max_updates Type: int(11) unsigned Null: NO Key:Default: 0 Extra:*************************** 38. row *************************** Field: max_connections Type: int(11) unsigned Null: NO Key:Default: 0 Extra:*************************** 39. row *************************** Field: max_user_connections Type: int(11) unsigned Null: NO Key:Default: 0 Extra:39 rows in set (0.00 sec) 这三个字段可以用GRANT语句来生成。
1、MAX_QUERIES_PER_HOUR 用来限制用户每小时运行的查询数量mysql> grant select on *.* to 'cu_blog'@'localhost' identified by '123456' withmax_queries_per_hour 5;Query OK, 0 rows affected (0.00 sec)...mysql> select user();+-------------------+| user() |+-------------------+| cu_blog@localhost |+-------------------+1 row in set (0.00 sec)当到了指定的次数时就会报错mysql> select user();ERROR 1226 (42000): User 'cu_blog' has exceeded the 'max_questions' resource (current value: 5)2、MAX_UPDATES_PER_HOUR 用来限制用户每小时的修改数据库数据的数量。mysql> grant select on *.* to 'cu_blog'@'localhost' with max_updates_per_hour 5;Query OK, 0 rows affected (0.00 sec)3、MAX_CONNECTIONS_PER_HOUR用来控制用户每小时打开新连接的数量。mysql> grant select on *.* to 'cu_blog'@'localhost' with max_connections_per_hour 5;Query OK, 0 rows affected (0.00 sec)4、MAX_USER_CONNECTIONS 限制有多少用户连接MYSQL服务器。mysql> grant select on *.* to 'cu_blog'@'localhost' with max_user_connections 2; Query OK, 0 rows affected (0.00 sec)
5、要想将所有账户当前的记数重设为零,可以执行FLUSH USER_RESOURCES语句。还可以通过重载授权表来重设记数。
mysql> flush user_resources;Query OK, 0 rows affected (0.00 sec)
|