How to change mysql/mariadb max_connections on boot

123

MySQL的max_connections參數用來設置最大連接(用戶)數。每個連接MySQL的用戶均算作一個連接,max_connections的默認值為100

與max_connections有關的特性

  • MySQL無論如何都會保留一個用於管理員(SUPER)登陸的連接,用於管理員連接數據庫進行維護操作,即使當前連接數已經達到了max_connections。因此MySQL的實際最大可連接數為max_connections+1;
  • 這個參數實際起作用的最大值(實際最大可連接數)為16384,即該參數最大值不能超過16384,即使超過也以16384為準;
  • 增加max_connections參數的值,不會佔用太多系統資源。系統資源(CPU、內存)的佔用主要取決於查詢的密度、效率等;
  • 該參數設置過小的最明顯特徵是出現“Too many connections”錯誤;

Command check current mysql connections:

SHOW VARIABLES LIKE "max_connections";

MariaDB [(none)]> SHOW VARIABLES LIKE “max_connections”;
+—————–+——-+
| Variable_name | Value |
+—————–+——-+
| max_connections | 100 |
+—————–+——-+

vi /etc/my.cnf

max_connections = 3000

systemctl restart mariadb

or

vi /etc/rc.local

mysql --user=root --password=your_password --execute='SET GLOBAL max_connections = 3000;'
Source MySQL性能調優 調整max_connections參數
Comments