forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…facebook#950) Summary: JIRA: https://jira.percona.com/browse/FB8-84 Reference Patch: facebook@478fa2a Reference Patch: facebook@8a269ee4f97 Reference Patch: facebook@c53bf248a27 Reference Patch: facebook@ae0d38ae0c8 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. Pull Request resolved: facebook#950 Reviewed By: lloyd Differential Revision: D13987618 Pulled By: lth
- Loading branch information
Showing
16 changed files
with
560 additions
and
3 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,113 @@ | ||
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 | ||
include/assert.inc [Non_super_connections should be 0] | ||
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 | ||
include/assert.inc [Non_super_connections should be 10] | ||
connection con_root; | ||
connection con_root; | ||
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 | ||
include/assert.inc [Non_super_connections should be 10] | ||
connection con_super; | ||
connection con_super; | ||
mysqltest: At line 1: Query 'change_user test_user' failed. | ||
ERROR 1040 (08004): 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; | ||
Verifying nonsuper_connections is decremented when db is denied | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
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 | ||
include/assert.inc [Non_super_connections should be 10] | ||
connection default; | ||
connection default; | ||
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
100 changes: 100 additions & 0 deletions
100
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,100 @@ | ||
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; | ||
SELECT @@global.max_nonsuper_connections; | ||
@@global.max_nonsuper_connections | ||
100000000000 | ||
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 | ||
100000000000 | ||
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 'local.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 'global.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 HY000: Variable 'max_nonsuper_connections' is a GLOBAL variable | ||
SELECT @@global.max_nonsuper_connections = VARIABLE_VALUE | ||
FROM performance_schema.global_variables | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
@@global.max_nonsuper_connections = VARIABLE_VALUE | ||
1 | ||
SELECT @@max_nonsuper_connections = VARIABLE_VALUE | ||
FROM performance_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_INCORRECT_GLOBAL_LOCAL_VAR | ||
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 performance_schema.global_variables | ||
WHERE VARIABLE_NAME='max_nonsuper_connections'; | ||
|
||
SELECT @@max_nonsuper_connections = VARIABLE_VALUE | ||
FROM performance_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.