-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global variable
max_nonsuper_connections
Summary: The new global variable `max_nonsuper_connections` will enforce the limit for the sum of all non-admin connections. This will be useful to limit regular user connections while still allow super users to connect to server. Closes #389 Reviewed By: anca-agape Differential Revision: D4123732 Pulled By: tianx fbshipit-source-id: 7ffb140
- Loading branch information
Showing
13 changed files
with
465 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
create user test_user@localhost; | ||
grant all on test to test_user@localhost; | ||
create user super_user@localhost; | ||
grant all on *.* to super_user@localhost with grant option; | ||
SET @start_value = @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = 10; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
10 | ||
connection default; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
ERROR 08004: Too many connections | ||
connect con_root, localhost, root,,test; | ||
# connection con_root | ||
connection con_root; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
10 | ||
disconnect con_root; | ||
connection default; | ||
connect con_super, localhost, super_user,,test; | ||
connection con_super; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
10 | ||
mysqltest: At line 1: change user failed: Too many connections | ||
disconnect con_super; | ||
connection con10; | ||
connect con11, localhost, test_user,,test; | ||
disconnect con11; | ||
connection con10; | ||
ERROR 08004: Too many connections | ||
connection default; | ||
disconnect con10; | ||
disconnect con9; | ||
disconnect con8; | ||
disconnect con7; | ||
disconnect con6; | ||
disconnect con5; | ||
disconnect con4; | ||
disconnect con3; | ||
disconnect con2; | ||
disconnect con1; | ||
connection default; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
ERROR 08004: Too many connections | ||
connection default; | ||
SET @@global.max_nonsuper_connections = @start_value; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
drop user test_user@localhost; | ||
drop user super_user@localhost; | ||
disconnect con10; | ||
disconnect con9; | ||
disconnect con8; | ||
disconnect con7; | ||
disconnect con6; | ||
disconnect con5; | ||
disconnect con4; | ||
disconnect con3; | ||
disconnect con2; | ||
disconnect con1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
mysql-test/suite/sys_vars/r/max_nonsuper_connections_basic.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
SET @start_value = @@global.max_nonsuper_connections; | ||
SELECT @start_value; | ||
@start_value | ||
0 | ||
SET @@global.max_nonsuper_connections = DEFAULT; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@global.max_nonsuper_connections = 100000; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
100000 | ||
SET @@global.max_nonsuper_connections = 99999; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
99999 | ||
SET @@global.max_nonsuper_connections = 65536; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
65536 | ||
SET @@global.max_nonsuper_connections = 1; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
1 | ||
SET @@global.max_nonsuper_connections = 2; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
2 | ||
SET @@global.max_nonsuper_connections = TRUE; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
1 | ||
SET @@global.max_nonsuper_connections = FALSE; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@global.max_nonsuper_connections = -1; | ||
Warnings: | ||
Warning 1292 Truncated incorrect max_nonsuper_connections value: '-1' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@global.max_nonsuper_connections = 100000000000; | ||
Warnings: | ||
Warning 1292 Truncated incorrect max_nonsuper_connections value: '100000000000' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
4294967295 | ||
SET @@global.max_nonsuper_connections = 10000.01; | ||
ERROR 42000: Incorrect argument type to variable 'max_nonsuper_connections' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
4294967295 | ||
SET @@global.max_nonsuper_connections = -1024; | ||
Warnings: | ||
Warning 1292 Truncated incorrect max_nonsuper_connections value: '-1024' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@global.max_nonsuper_connections = ON; | ||
ERROR 42000: Incorrect argument type to variable 'max_nonsuper_connections' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@global.max_nonsuper_connections = 'test'; | ||
ERROR 42000: Incorrect argument type to variable 'max_nonsuper_connections' | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 | ||
SET @@session.max_nonsuper_connections = 4096; | ||
ERROR HY000: Variable 'max_nonsuper_connections' is a GLOBAL variable and should be set with SET GLOBAL | ||
SELECT @@session.max_nonsuper_connections; | ||
ERROR HY000: Variable 'max_nonsuper_connections' is a GLOBAL variable | ||
SET max_nonsuper_connections = 6000; | ||
ERROR HY000: Variable 'max_nonsuper_connections' is a GLOBAL variable and should be set with SET GLOBAL | ||
SELECT @@max_nonsuper_connections; | ||
@@max_nonsuper_connections | ||
0 | ||
SET local.max_nonsuper_connections = 7000; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max_nonsuper_connections = 7000' at line 1 | ||
SELECT local.max_nonsuper_connections; | ||
ERROR 42S02: Unknown table 'local' in field list | ||
SET global.max_nonsuper_connections = 8000; | ||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max_nonsuper_connections = 8000' at line 1 | ||
SELECT global.max_nonsuper_connections; | ||
ERROR 42S02: Unknown table 'global' in field list | ||
SELECT max_nonsuper_connections = @@session.max_nonsuper_connections; | ||
ERROR 42S22: Unknown column 'max_nonsuper_connections' in 'field list' | ||
SELECT @@global.max_nonsuper_connections = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
@@global.max_nonsuper_connections = VARIABLE_VALUE | ||
1 | ||
SELECT @@max_nonsuper_connections = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
@@max_nonsuper_connections = VARIABLE_VALUE | ||
1 | ||
SET @@global.max_nonsuper_connections = @start_value; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
0 |
95 changes: 95 additions & 0 deletions
95
mysql-test/suite/sys_vars/t/max_nonsuper_connections_basic.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--source include/load_sysvars.inc | ||
|
||
# | ||
# save original value | ||
# | ||
SET @start_value = @@global.max_nonsuper_connections; | ||
SELECT @start_value; | ||
|
||
|
||
# | ||
# set default value | ||
# | ||
SET @@global.max_nonsuper_connections = DEFAULT; | ||
SELECT @@global.max_nonsuper_connections; | ||
|
||
|
||
# | ||
# set various values | ||
# | ||
SET @@global.max_nonsuper_connections = 100000; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = 99999; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = 65536; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = 1; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = 2; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = TRUE; | ||
SELECT @@global.max_nonsuper_connections; | ||
SET @@global.max_nonsuper_connections = FALSE; | ||
SELECT @@global.max_nonsuper_connections; | ||
|
||
|
||
# | ||
# set invalid values | ||
# | ||
# Value truncated | ||
SET @@global.max_nonsuper_connections = -1; | ||
SELECT @@global.max_nonsuper_connections; | ||
# Value truncated | ||
SET @@global.max_nonsuper_connections = 100000000000; | ||
SELECT @@global.max_nonsuper_connections; | ||
--Error ER_WRONG_TYPE_FOR_VAR | ||
SET @@global.max_nonsuper_connections = 10000.01; | ||
SELECT @@global.max_nonsuper_connections; | ||
# Value truncated | ||
SET @@global.max_nonsuper_connections = -1024; | ||
SELECT @@global.max_nonsuper_connections; | ||
|
||
--Error ER_WRONG_TYPE_FOR_VAR | ||
SET @@global.max_nonsuper_connections = ON; | ||
SELECT @@global.max_nonsuper_connections; | ||
--Error ER_WRONG_TYPE_FOR_VAR | ||
SET @@global.max_nonsuper_connections = 'test'; | ||
SELECT @@global.max_nonsuper_connections; | ||
|
||
--Error ER_GLOBAL_VARIABLE | ||
SET @@session.max_nonsuper_connections = 4096; | ||
--Error ER_INCORRECT_GLOBAL_LOCAL_VAR | ||
SELECT @@session.max_nonsuper_connections; | ||
|
||
--Error ER_GLOBAL_VARIABLE | ||
SET max_nonsuper_connections = 6000; | ||
SELECT @@max_nonsuper_connections; | ||
--Error ER_PARSE_ERROR | ||
SET local.max_nonsuper_connections = 7000; | ||
--Error ER_UNKNOWN_TABLE | ||
SELECT local.max_nonsuper_connections; | ||
--Error ER_PARSE_ERROR | ||
SET global.max_nonsuper_connections = 8000; | ||
--Error ER_UNKNOWN_TABLE | ||
SELECT global.max_nonsuper_connections; | ||
--Error ER_BAD_FIELD_ERROR | ||
SELECT max_nonsuper_connections = @@session.max_nonsuper_connections; | ||
|
||
|
||
# | ||
# Check if the value in GLOBAL & SESSION Tables matches values in variable | ||
# | ||
SELECT @@global.max_nonsuper_connections = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
|
||
SELECT @@max_nonsuper_connections = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
|
||
|
||
# | ||
# restore | ||
# | ||
SET @@global.max_nonsuper_connections = @start_value; | ||
SELECT @@global.max_nonsuper_connections; |
Oops, something went wrong.