Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[其他] MySQL 性能优化诊断脚本

[复制链接]
cookie 发表于 2011-9-23 21:59:50 | 显示全部楼层 |阅读模式

{:soso_e103:}

一个由MySQL职员写的优化脚本,可根据现有配置,系统配置,MySQL的运行情况给出优化建议。
  1. wget http://www.day32.com/MySQL/tuning-primer.sh
  2. chmod 755 tuning-primer.sh
  3. sh tuning-primer.sh
复制代码
akymakr 发表于 2011-9-24 02:28:41 | 显示全部楼层
請問 .sh 運行之後會有什麼結果出現?
回复

使用道具 举报

 楼主| cookie 发表于 2011-9-24 03:59:36 | 显示全部楼层
akymakr 发表于 2011-9-24 02:28
請問 .sh 運行之後會有什麼結果出現?

将tuning-primer.sh拷贝到my.cnf的同级目录
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
从上面的分析报告,以及建议可以看出,本机的mysql真的要好好调优一下了。

回复

使用道具 举报

fireseven 发表于 2011-9-24 19:10:25 | 显示全部楼层
怎么用呢?楼主说下
回复

使用道具 举报

祝你幸福 发表于 2011-9-25 00:08:50 | 显示全部楼层
本帖最后由 祝你幸福 于 2011-10-1 02:05 编辑

03的账号














齐齐哈尔
0452e
鹤城网
回复

使用道具 举报

jok2011 发表于 2011-9-27 09:15:19 | 显示全部楼层
本帖最后由 jok2011 于 2011-9-27 09:15 编辑
akymakr 发表于 2011-9-24 02:28
請問 .sh 運行之後會有什麼結果出現?


sh,是UNIX或linux下的shell脚本.类似于win下的批处理.希望对您有帮助.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-23 05:32 , Processed in 0.103965 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表