mysql打開文件數太多的解決辦法


http://www.orczhou.com/index.php/2010/10/mysql-open-file-limit/

 

http://www.cnblogs.com/end/archive/2013/02/02/2890018.html

 

然后, 以root身份重新啟動 mysqld. 在這里, 盡管 my.cnf 中指定的運行用戶不是root, 一樣可以以root身份來啟動mysqld, 否則 open_files_limit 選項無法生效, 因為內核限制了普通用戶的最多打開文件數.

 

 

判斷方法:

在系統運行一段時間后,可以通過show processlist命令查看當前系統的連接狀態,如果發現有大量的sleep狀態的連接進程,則說明該參數設置的過大,可以進行適當的調整小些。

http://blog.chinaunix.net/uid-24426415-id-77347.html
http://www.cnblogs.com/jiunadianshi/articles/2475475.html
http://www.cnblogs.com/jiunadianshi/articles/2388871.html
http://www.cnblogs.com/littlehb/p/5846701.html
===============================================================


注意事項:

1、為了防止發生too many connections時候無法登錄的問題,mysql manual有如下的說明:
mysqld actually allows max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected.

因此, 必須只賦予root用戶的SUPER權限,同時所有數據庫連接的帳戶不能賦予SUPER權限。前面說到的報錯后無法登錄就是由於我們的應用程序直接配置的root用戶。


2、修改MySQL配置文件/etc/my.cnf,設置成max_connections=1000,wait_timeout=10。如果沒有此項設置可以自行添加,修改后重啟MySQL服務即可。要不經常性報此錯誤,則要對服務器作整體性能優化。(單位是秒)


1)interactive_timeout:
參數含義:服務器關閉交互式連接前等待活動的秒數。交互式客戶端定義為在mysql_real_connect()中使用CLIENT_INTERACTIVE選項的客戶端。
參數默認值:28800秒(8小時)

(2)wait_timeout:
參數含義:服務器關閉非交互連接之前等待活動的秒數。
在線程啟動時,根據全局wait_timeout值或全局interactive_timeout值初始化會話wait_timeout值,取決於客戶端類型(由mysql_real_connect()的連接選項CLIENT_INTERACTIVE定義)。
參數默認值:28800秒(8小時)


查看的辦法:
show global variables like 'wait_timeout';

會話變量wait_timeout初始化的問題,這一點在手冊里已經明確指出了,我就直接拷貝了:
On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()).


建議配置:
【mysqld】
wait_timeout=100
interactive_timeout=100

http://www.cnblogs.com/jiunadianshi/articles/2475475.html

http://www.cnblogs.com/losesea/archive/2013/11/24/3440107.html



免責聲明!

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



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