2
# Test behavior of various per-account limits (aka quotas)
5
# Requires privileges to be enabled
9
drop table if exists t1;
11
create table t1 (i int);
12
# Just be sure that nothing will bother us
13
delete from mysql.user where user like 'mysqltest\_%';
14
delete from mysql.db where user like 'mysqltest\_%';
15
delete from mysql.tables_priv where user like 'mysqltest\_%';
16
delete from mysql.columns_priv where user like 'mysqltest\_%';
19
# Limits doesn't work with prepared statements (yet)
22
# Test of MAX_QUERIES_PER_HOUR limit
23
grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2;
24
# This ensures that counters are reset and makes test scheduling independent
26
connect (mqph, localhost, mysqltest_1,,);
32
connect (mqph2, localhost, mysqltest_1,,);
38
drop user mysqltest_1@localhost;
42
# Test of MAX_UPDATES_PER_HOUR limit
43
grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2;
45
connect (muph, localhost, mysqltest_1,,);
55
connect (muph2, localhost, mysqltest_1,,);
62
drop user mysqltest_1@localhost;
66
# Test of MAX_CONNECTIONS_PER_HOUR limit
67
grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2;
69
connect (mcph1, localhost, mysqltest_1,,);
72
connect (mcph2, localhost, mysqltest_1,,);
75
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
77
connect (mcph3, localhost, mysqltest_1,,);
78
# Old connection is still ok
80
# Let us try to close old connections and try again. This will also test that
81
# counters are not thrown away if there are no connections for this user.
84
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
86
connect (mcph3, localhost, mysqltest_1,,);
89
drop user mysqltest_1@localhost;
91
# Test of MAX_USER_CONNECTIONS limit
92
# We need this to reset internal mqh_used variable
94
grant usage on *.* to mysqltest_1@localhost with max_user_connections 2;
96
connect (muc1, localhost, mysqltest_1,,);
99
connect (muc2, localhost, mysqltest_1,,);
102
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
104
connect (muc3, localhost, mysqltest_1,,);
105
# Closing of one of connections should help
107
connect (muc3, localhost, mysqltest_1,,);
109
# Changing of limit should also help (and immediately)
111
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
112
flush user_resources;
113
connect (muc4, localhost, mysqltest_1,,);
116
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
118
connect (muc5, localhost, mysqltest_1,,);
124
drop user mysqltest_1@localhost;
126
# Now let us test interaction between global and per-account
127
# max_user_connections limits
128
select @@session.max_user_connections, @@global.max_user_connections;
129
# Local max_user_connections variable can't be set directly
130
# since this limit is per-account
132
set session max_user_connections= 2;
133
# But it is ok to set global max_user_connections
134
set global max_user_connections= 2;
135
select @@session.max_user_connections, @@global.max_user_connections;
136
# Let us check that global limit works
137
grant usage on *.* to mysqltest_1@localhost;
138
flush user_resources;
139
connect (muca1, localhost, mysqltest_1,,);
141
select @@session.max_user_connections, @@global.max_user_connections;
142
connect (muca2, localhost, mysqltest_1,,);
145
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
147
connect (muca3, localhost, mysqltest_1,,);
148
# Now we are testing that per-account limit prevails over gloabl limit
150
grant usage on *.* to mysqltest_1@localhost with max_user_connections 3;
151
flush user_resources;
152
connect (muca3, localhost, mysqltest_1,,);
154
select @@session.max_user_connections, @@global.max_user_connections;
155
--replace_result $MASTER_MYPORT DRIZZLE_PORT $MASTER_MYSOCK DRIZZLE_SOCK
157
connect (muca4, localhost, mysqltest_1,,);
163
set global max_user_connections= 0;
164
drop user mysqltest_1@localhost;