mysql監測工具tuning-primer.sh
mysql 的運算情況,我們可以一步一步的去查看,分析。這樣需要一定的時間,今天推薦給大家一個不錯的腳本tuning-primer.sh,可以幫助我們去查看一下msyql的運行情況,產生報告和給出一些建議,我們可以根據這些建議,結合mysql服務器的實際情況,對mysql進行優化。
一,下載以及使用
1,wget http://www.day32.com/MySQL/tuning-primer.sh
2,將tuning-primer.sh拷貝到my.cnf的同級目錄
3,sh tuning-primer.sh 或者 chmod +x tuning-primer.sh 然后在 ./tuning-primer.sh 二者沒什么區別
[root@BlackGhost mysql]# sh tuning-primer.sh
Using login values from ~/.my.cnf
- INITIAL LOGIN ATTEMPT FAILED -
Testing for stored webmin passwords:
None Found
Could not auto detect login info!
Found Sockets: /tmp/mysql.sock //找到一個mysql.sock
Using: /tmp/mysql.sock //使用這個.sock文件
Would you like to provide a different socket?: [y/N] n //是否使用其他的socket
Do you have your login handy ? [y/N] : y //是否手動輸入用戶名和密碼,當然你可以在my.cnf里面設置
User: root
Password:
Would you like me to create a ~/.my.cnf file for you? [y/N] : n //是不是要幫你在創建一個my.cnf
你也可以把用戶名和密碼放到my.cnf里面,如下
[client]
user = 用戶名
password = 密碼
socket = /tmp/mysql.sock
二,運行結果,以及部分分析和建議
我是以本機的mysql為例來進行測試的。
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.1.26-rc-log i686
Uptime = 0 days 0 hrs 0 min 28 sec
Avg. qps = 0
Total Questions = 15
Threads Connected = 1
Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations
告訴我服務運行還不超過48個小時,這樣不安全
To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.1/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 enabled.
Current long_query_time = 2.000000 sec.
You have 0 out of 36 that take longer than 2.000000 sec. to complete
Your long_query_time seems to be fine
BINARY UPDATE LOG (增加備份時的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 commands are run manually
Setting expire_logs_days will allow you to remove old binary logs automatically
See http://dev.mysql.com/doc/refman/5.1/en/purge-master-logs.html
Binlog sync is not enabled, you could loose binlog records during a server crash
告訴我binary log沒有設置生存時間,會一直保存下來,只到主服務器重起,并且binlog的同步并沒有激活,如果服務器崩潰binlog數據將丟失
WORKER THREADS (工作線程)
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS (最大連接數)
Current max_connections = 500
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
告訴我,目前已連接的最大連接和設置的最大連接的比率差不多是0%,建議我把最大連接設置小一點,可以節省一點內存
No InnoDB Support Enabled!
MEMORY USAGE (內存使用)
Max Memory Ever Allocated : 17 M
Configured Max Per-thread Buffers : 796 M
Configured Max Global Buffers : 16 M
Configured Max Memory Limit : 812 M
Physical Memory : 1003 M
Max memory limit seem to be within acceptable norms
KEY BUFFER (KEY緩存)
No key reads?!
Seriously look into using some indexes
Current MyISAM index space = 16 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 0
Key buffer free ratio = 88 %
Your key_buffer_size seems to be fine
QUERY CACHE (查詢緩存)
Query cache is supported but not enabled 查詢緩存是支持的,但是沒有激活
Perhaps you should set the query_cache_size 建議我設置一下query_cache_size的大小
SORT OPERATIONS (排序操作)
Current sort_buffer_size = 512 K
Current read_rnd_buffer_size = 512 K
No sort operations have been performed
Sort buffer seems to be fine
JOINS (連接)
Current join_buffer_size = 132.00 K
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly
OPEN FILES LIMIT (最大打開文件數)
Current open_files_limit = 2500 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
告訴我,如果大量使用myisam的話,把open_files_limit的大小設置成table_cache大小的2倍-3倍
Your open_files_limit value seems to be fine
TABLE CACHE (表緩存)
Current table_open_cache = 64 tables
Current table_definition_cache = 256 tables
You have a total of 506 tables
You have 64 open tables.
Current table_cache hit rate is 12%
, while 100% of your table cache is in use
You should probably increase your table_cache
You should probably increase your table_definition_cache value.
告訴我打開了多少文件,table_cache緩存的比率是多少,并建議我增加table_cache和table_definition_cache的值
TEMP TABLES (臨時表)
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 141 temp tables, 10% were created on disk
Created disk tmp tables ratio seems fine
TABLE SCANS (表掃描)
Current read_buffer_size = 256 K
Current table scan ratio = 12 : 1
read_buffer_size seems to be fine
TABLE LOCKING (表鎖定)
Current Lock Wait ratio = 0 : 225
Your table locking seems to be fine