MySQl 修改最大串連數

來源:互聯網
上載者:User

標籤:ide   handles   com   mysql串連   生效   mit   協助   重啟   導致   

今天使用ide連接線下MySQL報錯Can not connect to MySQL server. Too many connections,報錯很明確,與MySQL的串連數滿了。想想也是,每起一個服務都會建立MySQL串連池,佔用不少的長串連。用ide查看了一下,原來最大串連數才151,看來有必要改大一點了。

上網查了一下,修改方式有兩種

1.命令列修改

進入mysql後,set GLOBAL max_connections=1024; 即可立即生效,但是博主沒有使用這種方式,因為這種方法治標不治本,一點重啟mysql,最大串連數又會變回151

2.修改配置,然後重啟

vi /etc/m.cnf加入max_connections=1024,然後重啟mysql即可。

重啟後,很遺憾,max_connections變成了214,這就很詭異了。我把max_connections又分別設定成500和213,實際的max_connections分別是214和213。也就是說,在這台伺服器上,max_connections最大隻能是234,猜測是因為作業系統的限制導致max_connections最大隻能為213。博主翻了翻MySQl官方文檔(英語不好看文檔真是渾身難受),發現以下幾句話:

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

以我的英語水準,把上述語句概括起來就是,max_connections依託於作業系統,Linux系統必要時需要增加open-files-limit。萬萬沒想到啊,修改max_connections竟然要修改作業系統最大檔案描述符。

vi /usr/lib/systemd/system/mysqld.service加入

LimitNOFILE=50000

重啟MySQL

嗯,搞定了~

希望對大家有所協助,祝大家每天開心~

MySQl 修改最大串連數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.