您的位置:首页 > 编程语言 > PHP开发

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

2016-09-05 17:23 603 查看
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帐号都登录不了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐