MySQL參數最大連接數max_connections


1、查看最大連接數

復制代碼
 mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 58    |
| Threads_connected | 57    |   ###這個數值指的是打開的連接數
| Threads_created   | 3676  |
| Threads_running   | 4     |   ###這個數值指的是激活的連接數,這個數值一般遠低於connected數值
+-------------------+-------+
 
Threads_connected 跟show processlist結果相同,表示當前連接數。准確的來說,Threads_running是代表當前並發數
 
這是是查詢數據庫當前設置的最大連接數
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
 
可以在/etc/my.cnf里面設置數據庫的最大連接數
[mysqld]
max_connections = 1000
復制代碼

 

2、show status

   Threads_connected  當前的連接數
   Connections  試圖連接到(不管是否成功)MySQL服務器的連接數。
   Max_used_connections  服務器啟動后已經同時使用的連接的最大數量。

3、設置最大連接數

復制代碼

set GLOBAL max_connections=2000; set GLOBAL max_user_connections=1500; mysql> show global variables like "max%connections"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | max_connections | 2000 | | max_user_connections | 1500 | +----------------------+-------+ 2 rows in set (0.08 sec)
復制代碼

說明,

系統支持的最大連接max_connections

用戶能最大連接進來的數量max_user_connections

別忘記在配置文件里添加否則重啟失效

max_connections=1000;

max_user_connection=600

以上設置,為自己和其他用戶預留幾個連接空閑

 

4、修改/etc/my.cnf中的max_connections


5、show processlist   顯示當前正在執行的MySQL連接

 

6、mysqladmin -u<user> -p<pwd> -h<host> status

 

復制代碼
顯示當前MySQL狀態

   Uptime: 13131  Threads: 1  Questions: 22  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 1  Queries per second avg: 0.1


   mysqladmin -u<user> -p<pwd> -h<host> extended-status

   顯示mysql的其他狀態

+-----------------------------------+----------+
| Variable_name                     | Value    |
+-----------------------------------+----------+
| Aborted_clients                   | 0        |
| Aborted_connects               | 1        |
| Binlog_cache_disk_use       | 0        |
| Binlog_cache_use               | 0        |
| Bytes_received                   | 1152   |
| Bytes_sent                         | 10400 |
| Com_admin_commands      | 0        |
| Com_assign_to_keycache  | 0        |

.............................................................

.............................................................

| Threads_cached                 | 2        |
| Threads_connected            | 1        |
| Threads_created                | 3        |
| Threads_running                | 1        |
| Uptime                                | 13509    |
| Uptime_since_flush_status | 13509    |
+-----------------------------------+----------+
復制代碼

 

7、遇到最大連接數處理

[推薦] 使用 mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪個目錄下可以使用命令查找:whereis mysqladmin);

mysqladmin flush-hosts -h192.168.x.x -Pxxxx -uroot -pxxxx;

 

8、OS ulimit參數

[root@emsc ~]# ulimit -n
65535

 

參考

MYSQL 最大連接數設置-毛蟲小臭臭-51CTO博客 http://blog.51cto.com/moerjinrong/1969909

Mysql 查看連接數,狀態 最大並發數 - CSDN博客 https://blog.csdn.net/makang110/article/details/75226522

mysql 最大鏈接數 max_connections 設置-12917979-51CTO博客 http://blog.51cto.com/12927979/2047537


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM