MySQL參數最大鏈接數max_connections

一、查看最大鏈接數mysql

複製代碼
 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
複製代碼

 

二、show statussql

   Threads_connected  當前的鏈接數
   Connections  試圖鏈接到(無論是否成功)MySQL服務器的鏈接數。
   Max_used_connections  服務器啓動後已經同時使用的鏈接的最大數量。數據庫

三、設置最大鏈接數服務器

複製代碼

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_connectionsspa

用戶能最大鏈接進來的數量max_user_connections.net

別忘記在配置文件裏添加不然重啓失效code

max_connections=1000;blog

max_user_connection=600ssl

以上設置,爲本身和其餘用戶預留幾個鏈接空閒

 

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


五、show processlist   顯示當前正在執行的MySQL鏈接

 

六、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    |
+-----------------------------------+----------+
複製代碼

 

七、遇到最大鏈接數處理

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

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

 

八、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

相關文章
相關標籤/搜索