一、查看最大链接数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 | 1000 | +-----------------+-------+ 能够在/etc/my.cnf里面设置数据库的最大链接数 [mysqld] max_connections = 1000
二、show statussql
Threads_connected 当前的链接数
Connections 试图链接到(无论是否成功)MySQL服务器的链接数。
Max_used_connections 服务器启动后已经同时使用的链接的最大数量。数据库
三、设置最大链接数服务器
set GLOBAL max_connections=2000; set GLOBAL max_user_connections=1500; mysql> show global variables like "max%connections"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | max_connections | 2000 | | max_user_connections | 1500 | +----------------------+-------+ 2 rows in set (0.08 sec)
说明,并发
系统支持的最大链接max_connectionsspa
用户能最大链接进来的数量max_user_connections.net
别忘记在配置文件里添加不然重启失效code
max_connections=1000;blog
max_user_connection=600ssl
以上设置,为本身和其余用户预留几个链接空闲
四、修改/etc/my.cnf中的max_connections
五、show processlist 显示当前正在执行的MySQL链接
六、mysqladmin -u<user> -p<pwd> -h<host> status
显示当前MySQL状态 Uptime: 13131 Threads: 1 Questions: 22 Slow queries: 0 Opens: 16 Flush tables: 1 Open tables: 1 Queries per second avg: 0.1 mysqladmin -u<user> -p<pwd> -h<host> extended-status 显示mysql的其余状态 +-----------------------------------+----------+ | Variable_name | Value | +-----------------------------------+----------+ | Aborted_clients | 0 | | Aborted_connects | 1 | | Binlog_cache_disk_use | 0 | | Binlog_cache_use | 0 | | Bytes_received | 1152 | | Bytes_sent | 10400 | | Com_admin_commands | 0 | | Com_assign_to_keycache | 0 | ............................................................. ............................................................. | Threads_cached | 2 | | Threads_connected | 1 | | Threads_created | 3 | | Threads_running | 1 | | Uptime | 13509 | | Uptime_since_flush_status | 13509 | +-----------------------------------+----------+
七、遇到最大链接数处理
[推荐] 使用 mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪一个目录下可使用命令查找:whereis mysqladmin); mysqladmin flush-hosts -h192.168.x.x -Pxxxx -uroot -pxxxx;
八、OS ulimit参数
[root@emsc ~]# ulimit -n 65535
参考
MYSQL 最大链接数设置-毛虫小臭臭-51CTO博客 http://blog.51cto.com/moerjinrong/1969909
Mysql 查看链接数,状态 最大并发数 - CSDN博客 https://blog.csdn.net/makang110/article/details/75226522
mysql 最大连接数 max_connections 设置-12917979-51CTO博客 http://blog.51cto.com/12927979/2047537