mysql> SHOW PROCESSLIST; +----+------+-----------------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------------+------+---------+------+-------+------------------+ | 3 | root | localhost:50274 | test | Query | 0 | NULL | SHOW PROCESSLIST | +----+------+-----------------+------+---------+------+-------+------------------+ 1 row in set (0.00 sec) mysql>
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 58 |
| Threads_connected | 57 |###这个数值指的是打开的连接数
| Threads_created | 3676 |
| Threads_running | 4 |###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+-------------------+-------+
Threads_connected 跟show processlist结果相同,表示当前连接数。准确的来说,Threads_running是代表当前并发数
这是是查询数据库当前设置的最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+
法一:可以在/etc/my.cnf里面设置数据库的最大连接数
max_connections = 1000
法二:mysql> set global max_connections=1000;