日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL: ERROR 1040: Too many connections”的异常情况1

發布時間:2025/3/20 数据库 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL: ERROR 1040: Too many connections”的异常情况1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

很多開發人員都會遇見”MySQL: ERROR 1040: Too many connections”的異常情況,造成這種情況的一種原因是訪問量過高,MySQL服務器抗不住,這個時候就要考慮增加從服務器分散讀壓力;另一種原因就是MySQL配置文件中max_connections值過小

首先,我們來查看mysql的最大連接數:

?

1

2

3

4

5

6

7

mysql> show variables like '%max_connections%';

+-----------------+-------+

| Variable_name? | Value |

+-----------------+-------+

| max_connections | 151? |

+-----------------+-------+

1 row in set (0.00 sec)

其次,查看服務器響應的最大連接數:

?

1

2

3

4

5

6

7

mysql> show global status like 'Max_used_connections';

+----------------------+-------+

| Variable_name??? | Value |

+----------------------+-------+

| Max_used_connections | 2?? |

+----------------------+-------+

1 row in set (0.00 sec)

可以看到服務器響應的最大連接數為2,遠遠低于mysql服務器允許的最大連接數值。

對于mysql服務器最大連接數值的設置范圍比較理想的是:服務器響應的最大連接數值占服務器上限連接數值的比例值在10%以上,如果在10%以下,說明mysql服務器最大連接上限值設置過高。

?

1

Max_used_connections / max_connections * 100% = 2/151 *100% ≈ 1%

我們可以看到占比遠低于10%(因為這是本地測試服務器,結果值沒有太大的參考意義,大家可以根據實際情況設置連接數的上限值)。

再來看一下自己 linode VPS 現在(時間:2013-11-13 23:40:11)的結果值:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

mysql> show variables like '%max_connections%';

+-----------------+-------+

| Variable_name? | Value |

+-----------------+-------+

| max_connections | 151? |

+-----------------+-------+

1 row in set (0.19 sec)

mysql> show global status like 'Max_used_connections';

+----------------------+-------+

| Variable_name??? | Value |

+----------------------+-------+

| Max_used_connections | 44? |

+----------------------+-------+

1 row in set (0.17 sec)

這里的最大連接數占上限連接數的30%左右。

上面我們知道怎么查看mysql服務器的最大連接數值,并且知道了如何判斷該值是否合理,下面我們就來介紹一下如何設置這個最大連接數值。

方法1:

?

1

2

3

4

5

6

7

8

9

mysql> set GLOBAL max_connections=256;

Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%max_connections%';

+-----------------+-------+

| Variable_name? | Value |

+-----------------+-------+

| max_connections | 256? |

+-----------------+-------+

1 row in set (0.00 sec)

方法2:

修改mysql配置文件my.cnf,在[mysqld]段中添加或修改max_connections值:

max_connections=128
重啟mysql服務即可。

轉載于:https://my.oschina.net/u/2357525/blog/737620

總結

以上是生活随笔為你收集整理的MySQL: ERROR 1040: Too many connections”的异常情况1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。