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窗口登錄數據庫
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)
打開第二個窗口
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)
查看數據庫連接
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>
打開第三個窗口
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)
查看數據庫連接
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>
打開第四個窗口
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)
查看數據庫連接
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
總結
以上是生活随笔為你收集整理的mysql 连接数测试_mysql最大连接数试验的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Springboot整合Drools规则
- 下一篇: mysql集群初始化配置_集群Clust