mysql调整max_connections和max_user_connections及php模拟并发测试
2016-09-05 17:23
603 查看
php模拟创建大量mysql连接
max_mysql.php
link_mysql.php
mysql查看最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
查看当前连接数
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 58 |
| Threads_connected | 57 | ###这个数值指的是打开的连接数
| Threads_created | 3676 |
| Threads_running | 4 | ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+-------------------+-------+
当超过最大max_user_connections,会提示max_user_connections限制数时会提示 User big already has more than 'max_user_connections
当超过max_connections,会提示too many connection
调整max_connections和max_user_connections值
max_connections #整个mysql服务器的最大连接数,如果服务器的并发连接请求量比较大,建议调高此值
max_user_connections #每个数据库用户的最大连接,注意是以用户+主机为单位
interactive_timeout=60 #服务器关闭交互式连接前等待活动的秒数
wait_timeout=60 #服务器关闭非交互连接之前等待活动的秒数
注意:
1、响应连接数占上限连接数的85%左右,如果发现比例在10%以下,mysql服务器连接上线就设置得过高了
Max_used_connections / max_connections * 100% ≈ 85%
2、连接数据库不要用root帐号,且只有root有super权限,免得连接数过多root帐号都登录不了
max_mysql.php
<?php for($i=1;$i<=500;$i++){ exec("nohup php /var/www/html/big/link_mysql.php > /dev/null &"); } ?>
link_mysql.php
<?php $conn=mysql_pconnect("192.168.1.199","big","123456",true);//也可用mysql_connect("192.168.1.199","big","123456",true); sleep(1000); ?>
mysql查看最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
查看当前连接数
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 58 |
| Threads_connected | 57 | ###这个数值指的是打开的连接数
| Threads_created | 3676 |
| Threads_running | 4 | ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+-------------------+-------+
当超过最大max_user_connections,会提示max_user_connections限制数时会提示 User big already has more than 'max_user_connections
当超过max_connections,会提示too many connection
调整max_connections和max_user_connections值
max_connections #整个mysql服务器的最大连接数,如果服务器的并发连接请求量比较大,建议调高此值
max_user_connections #每个数据库用户的最大连接,注意是以用户+主机为单位
interactive_timeout=60 #服务器关闭交互式连接前等待活动的秒数
wait_timeout=60 #服务器关闭非交互连接之前等待活动的秒数
注意:
1、响应连接数占上限连接数的85%左右,如果发现比例在10%以下,mysql服务器连接上线就设置得过高了
Max_used_connections / max_connections * 100% ≈ 85%
2、连接数据库不要用root帐号,且只有root有super权限,免得连接数过多root帐号都登录不了
相关文章推荐
- MySQL中的max_connections和max_user_connections 及 MySQL服务器最大连接数的合理设置
- mysql 的max_connections和max_user_connections 的区别
- 合理设置max_user_connections以避免MySQL宕机
- mysql 的max_connections和max_user_connections 的区别
- [MySQL]记录一次线上故障处理过程--> has more than 'max_user_connections' active connections
- MySQL: Connection Refused,调整 mysql.ini中的 max_connections
- 解析mysql中max_connections与max_user_connections的区别
- [MySQL]记录一次线上故障处理过程--> has more than 'max_user_connections' active connections
- MySQL的max_user_connections拒绝连接的一次踩雷经验
- 解析mysql中max_connections与max_user_connections的区别
- mysql全局变量之max_connections & max_user_connections详解
- 解析mysql中max_connections与max_user_connections的区别
- MySQL中的max_connections和max_user_connections 及 MySQL服务器最大连接数的合理设置
- ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections
- MySQL性能优化之max_connections配置参数浅析
- mysql的limit max user processes
- MySQL性能优化之max_connections配置参数浅析
- 一个Web报表项目的性能分析和优化实践(六):设置MySQL的最大连接数(max_connections)
- 一个Web报表项目的性能分析和优化实践(六):设置MySQL的最大连接数(max_connections)
- 关于MYSQL数据库提示max_user_connections的错误解决办法