mysql 连接数测试_mysql最大连接数试验

一、试验基础环境配置

1、查看当前数据库的最大连接数

mysql> show global variables like '%connect%';+--------------------------+-----------------+

| Variable_name | Value |

+--------------------------+-----------------+

| character_set_connection | utf8 |

| collation_connection | utf8_general_ci |

| connect_timeout | 10 |

| init_connect | |

| max_connect_errors | 10 |

| max_connections | 160 |

| max_user_connections | 0 |

+--------------------------+-----------------+

7 rows in set (0.00 sec)

2、设置全局变量max_connections为3(基于试验目的,做测试)

mysql> set global max_connections=3;

Query OK,0 rows affected (0.01 sec)

3、查看设置是否生效.max_connections已经设置为3.

mysql> show global variables like '%connect%';+--------------------------+-----------------+

| Variable_name | Value |

+--------------------------+-----------------+

| character_set_connection | utf8 |

| collation_connection | utf8_general_ci |

| connect_timeout | 10 |

| init_connect | |

| max_connect_errors | 10 |

| max_connections |3 |

| max_user_connections | 0 |

+--------------------------+-----------------+

7 rows in set (0.00 sec)

4、退出当前登陆,再次登陆查看是否生效.

mysql> exitBye

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

Welcometo the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 3Server version:5.5.28MySQL Community Server (GPL)

Copyright (c)2000, 2012, Oracle and/or its affiliates. Allrights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

affiliates. Other names may be trademarksoftheir respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the currentinput statement.

mysql> show global variables like '%connect%';+--------------------------+-----------------+

| Variable_name | Value |

+--------------------------+-----------------+

| character_set_connection | utf8 |

| collation_connection | utf8_general_ci |

| connect_timeout | 10 |

| init_connect | |

| max_connect_errors | 10 |

| max_connections | 3 |

| max_user_connections | 0 |

+--------------------------+-----------------+

7 rows in set (0.00 sec)

二、查看当前数据库连接数

mysql> usearcerzhangdb;Databasechanged

mysql>show processlist;+----+------+-----------------+--------------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+-----------------+--------------+---------+------+-------+------------------+

| 3 | root | localhost:53232 | arcerzhangdb | Query | 0 | NULL | show processlist |

+----+------+-----------------+--------------+---------+------+-------+------------------+

1 row in set (0.00 sec)

三、分别打开第二个、第三个、第四个、第五个CMD窗口登录数据库

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

Welcometo the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 4Server version:5.5.28MySQL Community Server (GPL)

Copyright (c)2000, 2012, Oracle and/or its affiliates. Allrights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

affiliates. Other names may be trademarksoftheir respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the currentinput statement.

mysql> usearcerzhangdb;Databasechanged

mysql>show tables;+------------------------+

| Tables_in_arcerzhangdb |

+------------------------+

| inno_tab |

| t |

| t_myisam |

| tablespace_test |

| tt |

| ttt |

+------------------------+

6 rows in set (0.00sec)

mysql> desct;+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id | int(11) | NO | PRI | 0 | |

| name | varchar(10) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

2 rows in set (0.12 sec)

打开第二个窗口

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

mysql>show processlist;+----+------+-----------------+--------------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+-----------------+--------------+---------+------+-------+------------------+

| 3 | root | localhost:53232 | arcerzhangdb | Query | 0 | NULL | show processlist |

| 4 | root | localhost:53251 | arcerzhangdb | Sleep | 6 | | NULL |

+----+------+-----------------+--------------+---------+------+-------+------------------+

2 rows in set (0.00 sec)

查看数据库连接

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

Welcometo the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 5Server version:5.5.28MySQL Community Server (GPL)

Copyright (c)2000, 2012, Oracle and/or its affiliates. Allrights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

affiliates. Other names may be trademarksoftheir respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the currentinput statement.

mysql> usearcerzhangdb;Databasechanged

mysql> select * fromtt;+------+------+

| id | msg |

+------+------+

| 1 | a |

| 2 | b |

| 3 | c |

| 4 | d |

| 5 | e |

| 1000 | f |

+------+------+

6 rows in set (0.06sec)

mysql>

打开第三个窗口

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

mysql>show processlist;+----+------+-----------------+--------------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+-----------------+--------------+---------+------+-------+------------------+

| 3 | root | localhost:53232 | arcerzhangdb | Query | 0 | NULL | show processlist |

| 4 | root | localhost:53251 | arcerzhangdb | Sleep | 43 | | NULL |

| 5 | root | localhost:53264 | arcerzhangdb | Sleep | 5 | | NULL |

+----+------+-----------------+--------------+---------+------+-------+------------------+

3 rows in set (0.00 sec)

查看数据库连接

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

Welcometo the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 6Server version:5.5.28MySQL Community Server (GPL)

Copyright (c)2000, 2012, Oracle and/or its affiliates. Allrights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

affiliates. Other names may be trademarksoftheir respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the currentinput statement.

mysql> usearcerzhangdb;Databasechanged

mysql>show tables;+------------------------+

| Tables_in_arcerzhangdb |

+------------------------+

| inno_tab |

| t |

| t_myisam |

| tablespace_test |

| tt |

| ttt |

+------------------------+

6 rows in set (0.00sec)

mysql> select * fromttt;+----+------+

| id | msg |

+----+------+

| 1 | a |

+----+------+

1 row in set (0.07sec)

mysql>

打开第四个窗口

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

mysql>show processlist;+----+------+-----------------+--------------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+-----------------+--------------+---------+------+-------+------------------+

| 3 | root | localhost:53232 | arcerzhangdb | Query | 0 | NULL | show processlist |

| 4 | root | localhost:53251 | arcerzhangdb | Sleep | 97 | | NULL |

| 5 | root | localhost:53264 | arcerzhangdb | Sleep | 59 | | NULL |

| 6 | root | localhost:53274 | arcerzhangdb | Sleep | 5 | | NULL |

+----+------+-----------------+--------------+---------+------+-------+------------------+

4 rows in set (0.00 sec)

查看数据库连接

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

Microsoft Windows [版本 10.0.10586](c)2015Microsoft Corporation。保留所有权利。

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

ERROR1040(HY000): Too many connections

C:\Users\ArcerZhang>

打开第五个窗口

四、结论

第一个连接窗口为初始窗口,或者说叫做监控窗口.

第二个连接窗口应该算是我们设置max_connections=3后第一个真正意义上的连接用户.

第三个连接窗口应该算是我们设置max_connections=3后第二个真正意义上的连接用户.

第四个连接窗口应该算是我们设置max_connections=3后第三个真正意义上的连接用户.

所以当打开第五个窗口的时候,会报如下错误:

C:\Users\ArcerZhang>mysql -uroot -parcerzhang

ERROR1040 (HY000): Too many connections

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值