Loading mysql-test/r/user_limits.result +7 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ delete from mysql.tables_priv where user like 'mysqltest\_%'; delete from mysql.columns_priv where user like 'mysqltest\_%'; flush privileges; grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -16,6 +17,7 @@ select * from t1; ERROR 42000: User 'mysqltest_1' has exceeded the 'max_questions' resource (current value: 2) drop user mysqltest_1@localhost; grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -34,6 +36,7 @@ select * from t1; i drop user mysqltest_1@localhost; grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -47,6 +50,7 @@ ERROR 42000: User 'mysqltest_1' has exceeded the 'max_connections' resource (cur drop user mysqltest_1@localhost; flush privileges; grant usage on *.* to mysqltest_1@localhost with max_user_connections 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -56,6 +60,7 @@ ERROR 42000: User 'mysqltest_1' has exceeded the 'max_user_connections' resource select * from t1; i grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; select * from t1; i connect(localhost,mysqltest_1,,test,MYSQL_PORT,MYSQL_SOCK); Loading @@ -71,6 +76,7 @@ select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 2 2 grant usage on *.* to mysqltest_1@localhost; flush user_resources; select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 2 2 Loading @@ -79,6 +85,7 @@ i connect(localhost,mysqltest_1,,test,MYSQL_PORT,MYSQL_SOCK); ERROR 42000: User mysqltest_1 already has more than 'max_user_connections' active connections grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 3 2 Loading mysql-test/t/user_limits.test +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ flush privileges; # Test of MAX_QUERIES_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2; # This ensures that counters are reset and makes test scheduling independent flush user_resources; connect (mqph, localhost, mysqltest_1,,); connection mqph; select * from t1; Loading @@ -37,6 +39,7 @@ disconnect mqph2; # Test of MAX_UPDATES_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2; flush user_resources; connect (muph, localhost, mysqltest_1,,); connection muph; select * from t1; Loading @@ -60,6 +63,7 @@ disconnect muph2; # Test of MAX_CONNECTIONS_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2; flush user_resources; connect (mcph1, localhost, mysqltest_1,,); connection mcph1; select * from t1; Loading @@ -86,6 +90,7 @@ drop user mysqltest_1@localhost; # We need this to reset internal mqh_used variable flush privileges; grant usage on *.* to mysqltest_1@localhost with max_user_connections 2; flush user_resources; connect (muc1, localhost, mysqltest_1,,); connection muc1; select * from t1; Loading @@ -102,6 +107,7 @@ select * from t1; # Changing of limit should also help (and immediately) connection default; grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; connect (muc4, localhost, mysqltest_1,,); connection muc4; select * from t1; Loading @@ -127,6 +133,7 @@ set global max_user_connections= 2; select @@session.max_user_connections, @@global.max_user_connections; # Let us check that global limit works grant usage on *.* to mysqltest_1@localhost; flush user_resources; connect (muca1, localhost, mysqltest_1,,); connection muca1; select @@session.max_user_connections, @@global.max_user_connections; Loading @@ -139,6 +146,7 @@ connect (muca3, localhost, mysqltest_1,,); # Now we are testing that per-account limit prevails over gloabl limit connection default; grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; connect (muca3, localhost, mysqltest_1,,); connection muca3; select @@session.max_user_connections, @@global.max_user_connections; Loading sql/mysql_priv.h +1 −1 Original line number Diff line number Diff line Loading @@ -1001,7 +1001,7 @@ extern ulong ha_read_count, ha_discover_count; extern ulong table_cache_size; extern ulong max_connections,max_connect_errors, connect_timeout; extern ulong slave_net_timeout; extern ulong max_user_connections; extern uint max_user_connections; extern my_bool timed_mutexes; extern ulong what_to_log,flush_time; extern ulong query_buff_size, thread_stack,thread_stack_min; Loading sql/mysqld.cc +4 −3 Original line number Diff line number Diff line Loading @@ -333,7 +333,8 @@ ulong delayed_insert_errors,flush_time, thread_created; ulong specialflag=0; ulong binlog_cache_use= 0, binlog_cache_disk_use= 0; ulong max_connections,max_used_connections, max_connect_errors, max_user_connections = 0; max_connect_errors; uint max_user_connections= 0; ulong thread_id=1L,current_pid; my_bool timed_mutexes= 0; ulong slow_launch_threads = 0, sync_binlog_period; Loading Loading @@ -5255,8 +5256,8 @@ The minimum value for this variable is 4096.", REQUIRED_ARG, 32, 1, ~0L, 0, 1, 0}, {"max_user_connections", OPT_MAX_USER_CONNECTIONS, "The maximum number of active connections for a single user (0 = no limit).", (gptr*) &max_user_connections, (gptr*) &max_user_connections, 0, GET_ULONG, REQUIRED_ARG, 0, 1, ~0L, 0, 1, 0}, (gptr*) &max_user_connections, (gptr*) &max_user_connections, 0, GET_UINT, REQUIRED_ARG, 0, 1, ~0, 0, 1, 0}, {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT, "After this many write locks, allow some read locks to run in between.", (gptr*) &max_write_lock_count, (gptr*) &max_write_lock_count, 0, GET_ULONG, Loading sql/set_var.cc +8 −0 Original line number Diff line number Diff line Loading @@ -1599,6 +1599,14 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) var_type= OPT_GLOBAL; } switch (type()) { case SHOW_INT: { uint value; pthread_mutex_lock(&LOCK_global_system_variables); value= *(uint*) value_ptr(thd, var_type, base); pthread_mutex_unlock(&LOCK_global_system_variables); return new Item_uint((int32) value); } case SHOW_LONG: { ulong value; Loading Loading
mysql-test/r/user_limits.result +7 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ delete from mysql.tables_priv where user like 'mysqltest\_%'; delete from mysql.columns_priv where user like 'mysqltest\_%'; flush privileges; grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -16,6 +17,7 @@ select * from t1; ERROR 42000: User 'mysqltest_1' has exceeded the 'max_questions' resource (current value: 2) drop user mysqltest_1@localhost; grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -34,6 +36,7 @@ select * from t1; i drop user mysqltest_1@localhost; grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -47,6 +50,7 @@ ERROR 42000: User 'mysqltest_1' has exceeded the 'max_connections' resource (cur drop user mysqltest_1@localhost; flush privileges; grant usage on *.* to mysqltest_1@localhost with max_user_connections 2; flush user_resources; select * from t1; i select * from t1; Loading @@ -56,6 +60,7 @@ ERROR 42000: User 'mysqltest_1' has exceeded the 'max_user_connections' resource select * from t1; i grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; select * from t1; i connect(localhost,mysqltest_1,,test,MYSQL_PORT,MYSQL_SOCK); Loading @@ -71,6 +76,7 @@ select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 2 2 grant usage on *.* to mysqltest_1@localhost; flush user_resources; select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 2 2 Loading @@ -79,6 +85,7 @@ i connect(localhost,mysqltest_1,,test,MYSQL_PORT,MYSQL_SOCK); ERROR 42000: User mysqltest_1 already has more than 'max_user_connections' active connections grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; select @@session.max_user_connections, @@global.max_user_connections; @@session.max_user_connections @@global.max_user_connections 3 2 Loading
mysql-test/t/user_limits.test +8 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ flush privileges; # Test of MAX_QUERIES_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 2; # This ensures that counters are reset and makes test scheduling independent flush user_resources; connect (mqph, localhost, mysqltest_1,,); connection mqph; select * from t1; Loading @@ -37,6 +39,7 @@ disconnect mqph2; # Test of MAX_UPDATES_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 2; flush user_resources; connect (muph, localhost, mysqltest_1,,); connection muph; select * from t1; Loading @@ -60,6 +63,7 @@ disconnect muph2; # Test of MAX_CONNECTIONS_PER_HOUR limit grant usage on *.* to mysqltest_1@localhost with max_connections_per_hour 2; flush user_resources; connect (mcph1, localhost, mysqltest_1,,); connection mcph1; select * from t1; Loading @@ -86,6 +90,7 @@ drop user mysqltest_1@localhost; # We need this to reset internal mqh_used variable flush privileges; grant usage on *.* to mysqltest_1@localhost with max_user_connections 2; flush user_resources; connect (muc1, localhost, mysqltest_1,,); connection muc1; select * from t1; Loading @@ -102,6 +107,7 @@ select * from t1; # Changing of limit should also help (and immediately) connection default; grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; connect (muc4, localhost, mysqltest_1,,); connection muc4; select * from t1; Loading @@ -127,6 +133,7 @@ set global max_user_connections= 2; select @@session.max_user_connections, @@global.max_user_connections; # Let us check that global limit works grant usage on *.* to mysqltest_1@localhost; flush user_resources; connect (muca1, localhost, mysqltest_1,,); connection muca1; select @@session.max_user_connections, @@global.max_user_connections; Loading @@ -139,6 +146,7 @@ connect (muca3, localhost, mysqltest_1,,); # Now we are testing that per-account limit prevails over gloabl limit connection default; grant usage on *.* to mysqltest_1@localhost with max_user_connections 3; flush user_resources; connect (muca3, localhost, mysqltest_1,,); connection muca3; select @@session.max_user_connections, @@global.max_user_connections; Loading
sql/mysql_priv.h +1 −1 Original line number Diff line number Diff line Loading @@ -1001,7 +1001,7 @@ extern ulong ha_read_count, ha_discover_count; extern ulong table_cache_size; extern ulong max_connections,max_connect_errors, connect_timeout; extern ulong slave_net_timeout; extern ulong max_user_connections; extern uint max_user_connections; extern my_bool timed_mutexes; extern ulong what_to_log,flush_time; extern ulong query_buff_size, thread_stack,thread_stack_min; Loading
sql/mysqld.cc +4 −3 Original line number Diff line number Diff line Loading @@ -333,7 +333,8 @@ ulong delayed_insert_errors,flush_time, thread_created; ulong specialflag=0; ulong binlog_cache_use= 0, binlog_cache_disk_use= 0; ulong max_connections,max_used_connections, max_connect_errors, max_user_connections = 0; max_connect_errors; uint max_user_connections= 0; ulong thread_id=1L,current_pid; my_bool timed_mutexes= 0; ulong slow_launch_threads = 0, sync_binlog_period; Loading Loading @@ -5255,8 +5256,8 @@ The minimum value for this variable is 4096.", REQUIRED_ARG, 32, 1, ~0L, 0, 1, 0}, {"max_user_connections", OPT_MAX_USER_CONNECTIONS, "The maximum number of active connections for a single user (0 = no limit).", (gptr*) &max_user_connections, (gptr*) &max_user_connections, 0, GET_ULONG, REQUIRED_ARG, 0, 1, ~0L, 0, 1, 0}, (gptr*) &max_user_connections, (gptr*) &max_user_connections, 0, GET_UINT, REQUIRED_ARG, 0, 1, ~0, 0, 1, 0}, {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT, "After this many write locks, allow some read locks to run in between.", (gptr*) &max_write_lock_count, (gptr*) &max_write_lock_count, 0, GET_ULONG, Loading
sql/set_var.cc +8 −0 Original line number Diff line number Diff line Loading @@ -1599,6 +1599,14 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) var_type= OPT_GLOBAL; } switch (type()) { case SHOW_INT: { uint value; pthread_mutex_lock(&LOCK_global_system_variables); value= *(uint*) value_ptr(thd, var_type, base); pthread_mutex_unlock(&LOCK_global_system_variables); return new Item_uint((int32) value); } case SHOW_LONG: { ulong value; Loading