MySQL 默認(rèn)最大連接數(shù)是多少?
上午剛工作10分左右,同事說(shuō)在使用jira時(shí)出現(xiàn)問(wèn)題,具體截圖如下:

通過(guò)上圖的報(bào)錯(cuò)信息:定位為mysql數(shù)據(jù)庫(kù)連接數(shù)的問(wèn)題
解決方法:
1.登錄mysql進(jìn)行查看
Mysql –uroot –p123456
mysql> show variables like'%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
很奇怪,最大連接數(shù)怎么是151呢,mysql默認(rèn)的最大連接數(shù)不是100么?
后來(lái)想一下可能是版本不同的問(wèn)題,默認(rèn)連接數(shù)也不同。
為了確認(rèn)mysql5.5.3默認(rèn)的最大連接數(shù)為151,去mysql官網(wǎng)查看了一下:mysql默認(rèn)的最大連接數(shù)為151,上限為100000。另外,MySQL 系列面試題和答案我都整理好了,關(guān)注公眾號(hào)Java技術(shù)棧回復(fù) "面試" 獲取。
2.修改mysql默認(rèn)的最大連接數(shù)為1000
在/etc/my.cnf文件中[mysqld]部分增加max_connections=1000,重啟mysql服務(wù),問(wèn)題解決。
補(bǔ)充1:mysql其他版本默認(rèn)的最大連接數(shù)
Mysql5.5 mysql5.6 mysql5.7:默認(rèn)的最大連接數(shù)都是151,上限為:100000

Mysql5.1根據(jù)其小版本的不同,默認(rèn)的最大連接數(shù)和可修改的連接數(shù)上限也有所不同

Mysql5.0版本:默認(rèn)的最大連接數(shù)為100,上限為16384

補(bǔ)充2:修改mysql數(shù)據(jù)庫(kù)默認(rèn)的最大連接數(shù)
方法一:修改mysql的主配置文件/etc/my.cnf,[mysqld]部分添加“max_connections=1000(這個(gè)根據(jù)實(shí)際的需要來(lái)進(jìn)行設(shè)置即可)”,重啟mysql服務(wù)。
方法二:mysql客戶端登錄,通過(guò)命令行修改全局變量來(lái)進(jìn)行修改
mysql -uroot -p123456
mysql> set global_max_connections = 200;
mysql> show processlist;
mysql> show status;
修改完成后進(jìn)行查看,mysql的最大連接數(shù)
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.00 sec)
方法三:解開(kāi)mysql源代碼,進(jìn)入里面的SQL目錄修改mysqld.cc找到下面一行:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
0},
把它改為:
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
0},
保存退出,然后./configure ;make;make install可以獲得同樣的效果
方法四:通過(guò)修改mysqld_safe來(lái)修改mysql的連接數(shù)
編輯 mysqld_safe配置文件,找到如下內(nèi)容:
then $NOHUP_NICENESS $ledir/$MYSQLD
$defaults --basedir=$MY_BASEDIR_VERSION
--datadir=$DATADIR $USER_OPTION
--pid-file=$pid_file
--skip-external-locking
-O max_connections=1500
>> $err_log 2>&1 else
eval "$NOHUP_NICENESS $ledir/$MYSQLD
$defaults --basedir=$MY_BASEDIR_VERSION
--datadir=$DATADIR $USER_OPTION
--pid-file=$pid_file
--skip-external-locking $args
-O max_connections=1500 >>
$err_log 2>&1"
保存退出并重啟mysql服務(wù)。
參考文章:
http://blog.chinaunix.net/uid-20592013-id-94956.html
http://blog.csdn.net/tongle_deng/article/details/6932733
作者:mohan87821000
來(lái)源:https://blog.51cto.com/5250070/1672803
往期資源 需要請(qǐng)自取
喜歡就"在看"唄^_^
