2
# Test behavior of various per-account limits (aka quotas)
5
# Requires privileges to be enabled
6
-- source include/not_embedded.inc
10
drop table if exists t1;
12
create table t1 (i int);
13
# Just be sure that nothing will bother us
14
delete from mysql.user where user like 'mysqltest\_%';
15
delete from mysql.db where user like 'mysqltest\_%';
16
delete from mysql.tables_priv where user like 'mysqltest\_%';
17
delete from mysql.columns_priv where user like 'mysqltest\_%';
20
# Limits doesn't work with prepared statements (yet)
23
# Test of MAX_QUERIES_PER_HOUR limit
24
grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2;
25
# This ensures that counters are reset and makes test scheduling independent
27
connect (mqph, localhost, mysqltest_1,,);
33
connect (mqph2, localhost, mysqltest_1,,);
39
drop user mysqltest_1@localhost;
43
# Test of MAX_UPDATES_PER_HOUR limit
44
grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2;
46
connect (muph, localhost, mysqltest_1,,);
56
connect (muph2, localhost, mysqltest_1,,);
63
drop user mysqltest_1@localhost;
67
# Test of MAX_CONNECTIONS_PER_HOUR limit
68
grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2;
70
connect (mcph1, localhost, mysqltest_1,,);
73
connect (mcph2, localhost, mysqltest_1,,);
76
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
78
connect (mcph3, localhost, mysqltest_1,,);
79
# Old connection is still ok
81
# Let us try to close old connections and try again. This will also test that
82
# counters are not thrown away if there are no connections for this user.
85
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
87
connect (mcph3, localhost, mysqltest_1,,);
90
drop user mysqltest_1@localhost;
92
# Test of MAX_USER_CONNECTIONS limit
93
# We need this to reset internal mqh_used variable
95
grant usage on *.* to mysqltest_1@localhost with max_user_connections 2;
97
connect (muc1, localhost, mysqltest_1,,);
100
connect (muc2, localhost, mysqltest_1,,);
103
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
105
connect (muc3, localhost, mysqltest_1,,);
106
# Closing of one of connections should help
108
connect (muc3, localhost, mysqltest_1,,);
110
# Changing of limit should also help (and immediately)
112
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
113
flush user_resources;
114
connect (muc4, localhost, mysqltest_1,,);
117
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
119
connect (muc5, localhost, mysqltest_1,,);
125
drop user mysqltest_1@localhost;
127
# Now let us test interaction between global and per-account
128
# max_user_connections limits
129
select @@session.max_user_connections, @@global.max_user_connections;
130
# Local max_user_connections variable can't be set directly
131
# since this limit is per-account
133
set session max_user_connections= 2;
134
# But it is ok to set global max_user_connections
135
set global max_user_connections= 2;
136
select @@session.max_user_connections, @@global.max_user_connections;
137
# Let us check that global limit works
138
grant usage on *.* to mysqltest_1@localhost;
139
flush user_resources;
140
connect (muca1, localhost, mysqltest_1,,);
142
select @@session.max_user_connections, @@global.max_user_connections;
143
connect (muca2, localhost, mysqltest_1,,);
146
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
148
connect (muca3, localhost, mysqltest_1,,);
149
# Now we are testing that per-account limit prevails over gloabl limit
151
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
152
flush user_resources;
153
connect (muca3, localhost, mysqltest_1,,);
155
select @@session.max_user_connections, @@global.max_user_connections;
156
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
158
connect (muca4, localhost, mysqltest_1,,);
164
set global max_user_connections= 0;
165
drop user mysqltest_1@localhost;