1. 程式人生 > >MySQL 引數調優工具--tuning-primer

MySQL 引數調優工具--tuning-primer

 

最近發現了一款有意思的工具,tuning-primer.sh,它其實是一個指令碼。下載地址:http://www.day32.com/MySQL/tuning-primer.sh 

這個指令碼是通過 ”show statu like ...”  “show variables like ...” 獲取資訊,來生成一些伺服器引數調整的建議。目前它支援以下內容:

  • Slow Query Log
  • Max Connections
  • Worker Threads
  • Key Buffer
  • Query Cache
  • Sort Buffer
  • Joins
  • Temp Tables
  • Table (Open & Definition) Cache
  • Table Locking
  • Table Scans (read_buffer)
  • Innodb Status

 

使用的方法:

chmod 755 ./tuning-primer.sh

./tuning-primer.sh

執行前需要將密碼資訊寫入到配置檔案中:

[client]

user = root

password= 1234

socket = /usr/local/mysql/mysql.sock

在我伺服器上執行後的結果:

[
[email protected]
tools]# ./tuning-primer.sh -- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery - MySQL Version 5.6.40-log x86_64 Uptime = 1 days 22 hrs 33 min 29 sec Avg. qps = 0 Total Questions = 2226 Threads Connected = 1 Warning: Server has not been running for at least 48hrs. It may not be safe to use these recommendations To
find out more information on how each of these runtime variables effects performance visit: http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html Visit http://www.mysql.com/products/enterprise/advisors.html for info about MySQL's Enterprise Monitoring and Advisory Service SLOW QUERIES The slow query log is NOT enabled. Current long_query_time = 10.000000 sec. You have 0 out of 2247 that take longer than 10.000000 sec. to complete Your long_query_time seems to be fine BINARY UPDATE LOG The binary update log is enabled The expire_logs_days is not set. The mysqld will retain the entire binary log until RESET MASTER or PURGE MASTER LOGS commandsanually Setting expire_logs_days will allow you to remove old binary logs automatically See http://dev.mysql.com/doc/refman/5.6/en/purge-master-logs.html Binlog sync is not enabled, you could loose binlog records during a server crash WORKER THREADS Current thread_cache_size = 9 Current threads_cached = 0 Current threads_per_sec = 0 Historic threads_per_sec = 0 Your thread_cache_size is fine MAX CONNECTIONS Current max_connections = 151 Current threads_connected = 1 Historic max_used_connections = 1 The number of used connections is 0% of the configured maximum. You are using less than 10% of your configured max_connections. Lowering max_connections could help to avoid an over-allocation of memory See "MEMORY USAGE" section to make sure you are not over-allocating ...

 

從上面的紅色部分可以看到,我MySQL伺服器有兩個問題:

1.沒有設定 expire_logs_days 引數

2.max_connections 引數可能過大

 

根據這個指令碼的輸出資訊,能夠清晰的看到MySQL的引數設定是否合理。再根據我們的需要來決定是否調整。

另外這個指令碼已經很老了,我在github上找到了它的新版(不是原作者更新維護),地址是:https://github.com/BMDan/tuning-primer.sh