账号资源的限制:
max_queries_per_hour
该参数设置一个用户在一小时内可以执行查询的次数(基本包含所有语句)
max_updates_per_hour
该参数设置一个用户在一小时内可以执行修改的次数(仅包含修改数据库或表的语句)。
max_connections_per_hour
该参数设置一个用户在一小时内可以连接MySQL的时间。
max_user_connections
该参数作用是设置所有用户在同一时间连接MySQL实例的最大连接数限制。但这个参数无法对每个用户区别对待。
当某个用户的max_user_connections非0时,则忽略全局系统参数对应的配置,反之则使用全局参数。
mysql> create user temp@'%' identified by 'temp' WITH MAX_QUERIES_PER_HOUR 20 MAX_UPDATES_PER_HOUR 10 MAX_CONNECTIONS_PER_HOUR 5 MAX_USER_CONNECTIONS 2;
Query OK, 0 rows affected (0.06 sec)
mysql> SELECT u.Host,u.User,u.max_questions,u.max_updates,u.max_connections,u.max_user_connections FROM mysql.user u WHERE u.user='temp';
+------+------+---------------+-------------+-----------------+----------------------+
| Host | User | max_questions | max_updates | max_connections | max_user_connections |
+------+------+---------------+-------------+-----------------+----------------------+
| % | temp | 20 | 10 | 5 | 2 |
+------+------+---------------+-------------+-----------------+----------------------+
1 row in set (0.00 sec)
mysql> show variables like '%max_user_connections%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| max_user_connections | 3 |
+----------------------+-------+
1 row in set (0.01 sec)
取消某项资源限制既把原先的值改成0,0表示不限制资源。
mysql> alter user temp@'%' identified by 'temp' WITH MAX_QUERIES_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
Query OK, 0 rows affected (0.09 sec)
mysql> SELECT u.Host,u.User,u.max_questions,u.max_updates,u.max_connections,u.max_user_connections FROM mysql.user u WHERE u.user='temp';
+------+------+---------------+-------------+-----------------+----------------------+
| Host | User | max_questions | max_updates | max_connections | max_user_connections |
+------+------+---------------+-------------+-----------------+----------------------+
| % | temp | 0 | 0 | 0 | 0 |
+------+------+---------------+-------------+-----------------+----------------------+
1 row in set (0.00 sec)
总结:账号的资源限制除非是做精细化管理,否则在测试生产环境上的功能都比较鸡肋。创建账号使用默认设置即可。
MySQL 账号资源的限制
最新推荐文章于 2023-06-25 14:01:18 发布