MySQL 默認最大連接數(shù)是多少?
點擊上方藍色“肉眼品世界”,選擇“設為星標” 深度價值體系傳遞!
上午剛工作10分左右,同事說在使用jira時出現(xiàn)問題,具體截圖如下:

通過上圖的報錯信息:定位為mysql數(shù)據(jù)庫連接數(shù)的問題
解決方法:
1.登錄mysql進行查看
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默認的最大連接數(shù)不是100么?后來想一下可能是版本不同的問題,默認連接數(shù)也不同。為了確認mysql5.5.3默認的最大連接數(shù)為151,去mysql官網(wǎng)查看了一下:mysql默認的最大連接數(shù)為151,上限為1000
2.修改mysql默認的最大連接數(shù)為1000
在/etc/my.cnf文件中[mysqld]部分增加max_connections=1000,重啟mysql服務,問題解決。
補充1:mysql其他版本默認的最大連接數(shù)
Mysql5.5 mysql5.6 mysql5.7:默認的最大連接數(shù)都是151,上限為:100000

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

補充2:修改mysql數(shù)據(jù)庫默認的最大連接數(shù)
方法一:修改mysql的主配置文件/etc/my.cnf,[mysqld]部分添加“max_connections=1000(這個根據(jù)實際的需要來進行設置即可)”,重啟mysql服務。
方法二:mysql客戶端登錄,通過命令行修改全局變量來進行修改
mysql -uroot -p123456
mysql> set global_max_connections = 200;
mysql> show processlist;
mysql> show status;
修改完成后進行查看,mysql的最大連接數(shù)
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.00 sec)
方法三:解開mysql源代碼,進入里面的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可以獲得同樣的效果
方法四:通過修改mysqld_safe來修改mysql的連接數(shù)
編輯 mysqld_safe配置文件,找到如下內容:
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服務。
推薦閱讀:

