MYSQL中限制资源的使用

今天看到手册,不当心看到了这里,本身作了几个例子。

从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语句来生成。

一、MAX_QUERIES_PER_HOUR 用来限制用户每小时运行的查询数量

mysql> grant select on *.* to 'cu_blog'@'localhost' identified by '123456' with

max_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 (cu

rrent value: 5)

二、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)

三、MAX_CONNECTIONS_PER_HOUR用来控制用户每小时打开新链接的数量。

mysql> grant select on *.* to 'cu_blog'@'localhost' with max_connections_per_hou

r 5;

Query OK, 0 rows affected (0.00 sec)

四、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)


五、要想将全部帐户当前的记数重设为零,能够执行FLUSH USER_RESOURCES语句。还能够经过重载受权表来重设记数。

mysql> flush user_resources;

Query OK, 0 rows affected (0.00 sec)

相关文章
相关标签/搜索