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> exit
Bye

C:\Users\ArcerZhang>mysql -uroot -parcerzhang
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.28 MySQL Community Server (GPL)

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input 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> use arcerzhangdb;
Database changed
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
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.28 MySQL Community Server (GPL)

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> use arcerzhangdb;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_arcerzhangdb |
+------------------------+
| inno_tab               |
| t                      |
| t_myisam               |
| tablespace_test        |
| tt                     |
| ttt                    |
+------------------------+
6 rows in set (0.00 sec)

mysql> desc t;
+-------+-------------+------+-----+---------+-------+
| 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
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.28 MySQL Community Server (GPL)

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> use arcerzhangdb;
Database changed
mysql> select * from tt;
+------+------+
| id   | msg  |
+------+------+
|    1 | a    |
|    2 | b    |
|    3 | c    |
|    4 | d    |
|    5 | e    |
| 1000 | f    |
+------+------+
6 rows in set (0.06 sec)

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
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.28 MySQL Community Server (GPL)

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> use arcerzhangdb;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_arcerzhangdb |
+------------------------+
| inno_tab               |
| t                      |
| t_myisam               |
| tablespace_test        |
| tt                     |
| ttt                    |
+------------------------+
6 rows in set (0.00 sec)

mysql> select * from ttt;
+----+------+
| id | msg  |
+----+------+
|  1 | a    |
+----+------+
1 row in set (0.07 sec)

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) 2015 Microsoft Corporation。保留所有权利。

C:\Users\ArcerZhang>mysql -uroot -parcerzhang
ERROR 1040 (HY000): Too many connections

C:\Users\ArcerZhang>

打开第五个窗口

四、结论

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

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

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

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

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

C:\Users\ArcerZhang>mysql -uroot -parcerzhang
ERROR 1040 (HY000): Too many connections
时间: 2024-10-07 15:57:37

mysql最大连接数试验的相关文章

mysql优化-mysql最大连接数

########################### 修改mysql最大连接数 ############################### MYSQL数据库安装完成后,默认最大连接数是100, 一般生产环境的论坛或网站是远远不够的,以下提供两种修改MYSQL最大连接数的方法 ---------------------- 方法1:在线修改mysql最大连接数 --------------------------- 特点:对于mysql在使用中无法停机重启的情况,可以在mysql运行情况下修改

修改MYSQL最大连接数的2种方法

mysql默认最大连接数是100,增加加默认MYSQL连接数的方法有两个 方法一:进入MYSQL安装目录 打开MYSQL配置文件 my.ini(windows) 或 my.cnf(linux环境)查找 max_connections=100   修改为 max_connections=1000 服务里重起MYSQL即可 方法二: 客户端登录:mysql -u username -p password 设置新的最大连接数为200:mysql> set GLOBAL max_connections=

如何实时查看mysql当前连接数?

如何实时查看mysql当前连接数?  1.查看当前所有连接的详细资料: ./mysqladmin -uadmin -p -h10.140.1.1 processlist2.只查看当前连接数(Threads就是连接数.): ./mysqladmin  -uadmin -p -h10.140.1.1 status .查看当前所有连接的详细资料: mysqladmin -uroot -proot processlist D:\MySQL\bin>mysqladmin -uroot -proot pro

修改MySQL最大连接数

mysql -uroot -pgameol32!    或者 mysql -uroot -p    再输入密码            进入mysql控制台 mysql控制台模式下: show status;    查看mysql所有状态 show processlist;     普通用户自己的当前连接数,root用户可以查看所有用户的当前连接数 show status like '%connections%';    关键字查找 shell命令行模式下: mysqladmin -uroot -

CentOS下mysql最大连接数设置 1040 too many connection

当最大连接数比较小时,可能会出现"1040 too many connection"错误. 可以通过修改配置文件来修改最大连接数,但我连配置文件在哪都不知道,应该怎么办呢? 首先需要重启mysql服务,执行命令:service mysql restart 也有可能是:service mysqld restart 登录mysql:mysql -uroot -p输入密码,回车: 登录成功后执行以下语句查询当前的最大连接数:select VARIABLE_VALUE from informa

Mysql查看连接数相关信息

MySQL查看连接数相关信息在 数据库:INFORMATION_SCHEMA 表:PROCESSLIST 表结构如下: mysql> desc PROCESSLIST; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | I

怎么实时查看mysql当前连接数

如何实时查看mysql当前连接数? 如何实时查看mysql当前连接数? 1.查看当前所有连接的详细资料: ./mysqladmin -uadmin -p -h10.140.1.1 processlist 2.只查看当前连接数(Threads就是连接数.): ./mysqladmin -uadmin -p -h10.140.1.1 status .查看当前所有连接的详细资料: mysqladmin -uroot -proot processlist D:\MySQL\bin>mysqladmin

修改Oracle,mysql最大连接数

1.修改Oracle最大连接数的方法 a.以sysdba身份登陆PL/SQL 或者 Worksheet b.查询目前连接数 show parameter processes; c.更改系统连接数 alter system set processes=1000 scope=spfile; d.创建pfile create pfile from spfile; e.重启Oracle服务或重启Oracle服务器 2.查询Oracle游标使用情况的方法 select * from v$open_curs

MySQL的连接数

我使用的数据库,没有针对其进行其他相关设置,最近经常出现连接异常,现象为太多的连接. MySQL查看最大连接数和修改最大连接数 1.查看最大连接数(可通过show variables查看其他的全局参数).通常,mysql的最大连接数默认是100, 最大可以达到16384. show variables like '%max_connections%'; 显示变量信息,可选择范围,global | session | local ,紧跟show后面 2.修改最大连接数 set GLOBAL max