mysql ERROR 1040: Too many connections

來源:互聯網
上載者:User


錯提示如下

#/home/binbin.zhengbb/ssh/update_dns.sh

ERROR 1040 (08004): Too many connections

ERROR 1040 (08004): Too many connections

出現此錯誤的原因,一種是訪問量確實很高,MySQL伺服器頂不住,這個時候就要考慮增加從伺服器分散讀壓力,另外一種情況是MySQL設定檔中max_connections值過小。
查詢MySQL的最大串連數:

 代碼如下 複製代碼

    mysql> show variables like 'max_connections';
    +-----------------+-------+
    | Variable_name | Value |
    +-----------------+-------+
    | max_connections | 100 |
    +-----------------+-------+
    1 row in set (0.00 sec)

查詢MySQL響應的最大串連數:

 代碼如下 複製代碼

    mysql> show global status like 'max_used_connections';
    +----------------------+-------+
    | Variable_name | Value |
    +----------------------+-------+
    | Max_used_connections | 5 |
    +----------------------+-------+
    1 row in set (0.00 sec)

說明:本地環境沒什麼參考價值,但是就上面的資料而言,MySQL過去所響應的最大串連數小於其允許的最大串連數,所以不會出現1040錯誤。
MySQL比較理想的最大串連數計算方式為:

    max_used_connections / max_connections * 100% ≈ 85%

即最大串連數占上限串連數的85%左右,如果發現比例在10%以下,MySQL伺服器串連數上限設定的過高了。

方法一:直接修改mysql

 

 代碼如下 複製代碼

mysql> show variables;

| max_connections                 | 100   

mysql> set GLOBAL max_connections=1500;

 

方法二:修改設定檔

 代碼如下 複製代碼

[Intranet root@inc-dp-149-47 /root]

#vi /etc/my.cnf

 

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

log-bin=/var/lib/mysql/mysql_bin_log/log-bin

expire_logs_days=7

log-slow-queries=/var/log/mysqld_slow_query.log

set-variable=max_connections=1500

 

[mysqld_safe]

log-error=/var/log/mysqld.log

#log-update=/var/log/mysqld_update.log

pid-file=/var/run/mysqld/mysqld.pid

最後重啟我們的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.