mysql调整max_connections和max_user_connections及php模拟并发测试

php模拟创建大量mysql连接
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帐号都登录不了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值