當前位置:編程學習大全網 - 源碼下載 - 修改php.ini如何實現Mysql導入數據庫文件最大限制的修改方法

修改php.ini如何實現Mysql導入數據庫文件最大限制的修改方法

非root用戶運行MySQL,當MySQL配置比較高時,MySQL運行中生效的參數值與配置的值不壹樣,所以具體分析壹下MySQL是怎麽調整這些參數值的。?這篇文章的目的是為了說明在系統資源不夠的情況下,MySQL 是怎麽調整者三個參數的。說明此文涉及到三個參數open_files_limit、?max_connections、?table_open_cache。與這三個參數相關的系統資源是打開文件數限制,即文件描述符(fd)限制。系統參數與文件描述符的關系?-?max_connection?&?fd?: 每壹個MySQL connection ?都需要壹個文件描述符;-?table_open_cache?&?fd?打開壹張表至少需要壹個 ?文件描述符,如打開MyISAM需要兩個fd?;- 系統最大打開文件數可以通過?ulimit -n查看。MySQL調整參數的方式

根據配置(三個參數的配置值或默認值)計算?request_open_files(需要的文件描述符);

2.獲取有效的系統的限制值effective_open_files;? 3.根據effective_open_files調整request_open_files;? 4.根據調整後的request_open_files,計算實際生效的參數值(show variables?可查看參數值)。計算request_open_filesrequest_open_files有三個計算公式:1. ?// 最大連接數+同時打開的表的最大數量+其他(各種日誌等等)2. limit_1= max_connections+table_cache_size * 2 + 10;3. 4. ?//假設平均每個連接打開的表的數量(2-4)5. ?//源碼中是這麽寫的:6. ?//We are trying to allocate no less than?7. ? // max_connections*5 file handles8. ?limit_2= max_connections * 5;9. 10. //mysql 默認的默認是500011. limit_3= open_files_limit ? open_files_limit : 5000;12. ?13. 所以open_files_limit期待的最低14. request_open_files= max(limit_1,limit_2,limit_3);計算effective_open_files:MySQL 的思路:?

在有限值的的範圍內MySQL?盡量將effective_open_files的值設大。

修正request_open_files

requested_open_files= min(effective_open_files,?request_open_files)

重新計算參數值

修正open_files_limit

open_files_limit?=?effective_open_files

修正max_connections

max_connections?根據?request_open_files?來做修正。1.? limit = requested_open_files - 10 - TABLE_OPEN_CACHE_MIN * 2;

如果配置的max_connections值大於limit,則將max_connections?的值修正為limit

其他情況下?max_connections?保留配置值?

修正table_cache_size

table_cache_size?會根據?request_open_files?來做修正1. ?// mysql table_cache_size 最小值,4002. ? limit1 = TABLE_OPEN_CACHE_MIN3. ?// 根據 requested_open_files 計算4. ? limit2 = (requested_open_files - 10 - max_connections) / 25. ? limit = max(limit1,limt2);

如果配置的table_cache_size?值大於limit,則將?table_cache_size?的值修正為limit

其他情況下table_cache_size?保留配置值

舉例

以下用例在非 root 用戶下運行

參數設置:

//mysql

max_connections = 500

table_open_cache = 999

//ulimit -n?

1500

生效的值:

open_files_limit = 1500 max_connections = min[(1500 - 10 - 800),500] = 500

table_open_cache = ( 1500 - 10 - 500) / 2 =495

  • 上一篇:刷題庫平臺源代碼
  • 下一篇:java到底學什麽?怎麽學,具體要學習哪些?
  • copyright 2024編程學習大全網