max_user_connections与max_connections

max_user_connections针对单一用户

max_connections针对所有用户

用一个脚本可以验正

 cat test.sh

mysql -uroot -p3306 -e "show variables like '%max%connections'"
for i in {1..4}
do
mysql -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 connections
ERROR 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()	3
0	2015-03-10 12:32:39	test@localhost	3
+----------+---------------------+----------------+---+
| sleep(1) | sysdate()           | user()         | 2 |
+----------+---------------------+----------------+---+
|        0 | 2015-03-10 12:32:39 | root@localhost | 2 |
+----------+---------------------+----------------+---+
sleep(1)	sysdate()	user()	2
0	2015-03-10 12:32:39	test@localhost	2
sleep(1)	sysdate()	user()	4
0	2015-03-10 12:32:39	test@localhost	4

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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值