mysql 连接数 max_user_connections 和 max_connections
参数解释
max_connections: 当前数据库能够连接的所有连接数,不区分用户。
max_user_connections: 当前数据库用户所能连接的连接数限制,不会超过 max_connections。0 表示不限制
查看目前服务器的连接数限制设定
mysql> show variables like '%conn%'; +-----------------------------------------------+-------------------+ | Variable_name | Value | +-----------------------------------------------+-------------------+ | character_set_connection | latin1 | | collation_connection | latin1_swedish_ci | | connect_timeout | 10 | | disconnect_on_expired_password | ON | | init_connect | | | max_connect_errors | 100 | | max_connections | 10000 | | max_user_connections | 1000 | | performance_schema_session_connect_attrs_size | 512 | +-----------------------------------------------+-------------------+ 9 rows in set (0.00 sec)
查看数据库当前运行状态
mysql> show status like 'Threads%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 58 | | Threads_connected | 57 | ###这个数值指的是当前打开的连接数 | Threads_created | 3676 | | Threads_running | 4 | ###这个数值指的是当前运行的连接数,这个数值一般远低于connected数值 +-------------------+-------+
hreads_connected 跟 show processlist 结果相同,表示当前连接数。准确的来说,Threads_running 是代表当前并发数
设置 my.cnf(生效需重启)
在[mysqld]下面添加:
[mysqld] max_connections = 10000 max_user_connections = 2000
设置 变量(不重启生效)
mysql> set global max_connections=10000; mysql> set global max_user_connections=1000 ;
设置不当的报错
max_user_connections 设置不当报错
root@dg ~]# mysql -uroot -pmysql ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections
max_connections 设置不当报错
[root@dg ~]# mysql -uu2 -pu2 ERROR 1040 (HY000): Too many connections
系统限制
这两个参数还收到系统 limits 的限制
vim /etc/security/limits.conf mysql hard nofile 65535 mysql soft nofile 65535
0顶
0 踩
共 0 条评论