max_user_connections与max_connections

来源:互联网 发布:淘宝网包包新款男士 编辑:程序博客网 时间:2024/04/27 13:55

max_user_connections针对单一用户

max_connections针对所有用户

用一个脚本可以验正

 cat test.sh

mysql -uroot -p3306 -e "show variables like '%max%connections'"for i in {1..4}domysql -utest -ptest -e "select sleep(1),sysdate(),user(),'$i'" &mysql -uroot -p3306 -e "select sleep(1),sysdate(),user(),'$i'" &done

sh test.sh 

Warning: Using a password on the command line interface can be insecure.+----------------------+-------+| Variable_name        | Value |+----------------------+-------+| max_connections      | 151   || max_user_connections | 3     |+----------------------+-------+Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.[root@o11204 tmp]# Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.ERROR 1203 (42000): User root already has more than 'max_user_connections' active connectionsERROR 1203 (42000): User test already has more than 'max_user_connections' active connections+----------+---------------------+----------------+---+| sleep(1) | sysdate()           | user()         | 3 |+----------+---------------------+----------------+---++----------+---------------------+----------------+---+|        0 | 2015-03-10 12:32:39 | root@localhost | 3 |+----------+---------------------+----------------+---+| sleep(1) | sysdate()           | user()         | 4 |+----------+---------------------+----------------+---+|        0 | 2015-03-10 12:32:39 | root@localhost | 4 |+----------+---------------------+----------------+---+sleep(1)sysdate()user()302015-03-10 12:32:39test@localhost3+----------+---------------------+----------------+---+| sleep(1) | sysdate()           | user()         | 2 |+----------+---------------------+----------------+---+|        0 | 2015-03-10 12:32:39 | root@localhost | 2 |+----------+---------------------+----------------+---+sleep(1)sysdate()user()202015-03-10 12:32:39test@localhost2sleep(1)sysdate()user()402015-03-10 12:32:39test@localhost4

可以看到当第四次连接时不管root还是test用户都报错,而这时总用户已超过了3个

而由上面的例子也可以看到,后台程序执行的先后顺序,与脚本里发出的顺序不一样

在这儿 i=1 是最后一次执行,所以没出结果

0 0
原创粉丝点击