MySQL 脚本优化工具tuning-primer.sh使用教程说明

今天推荐给大家一个不错的脚本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

从上面的分析报告,以及建议可以看出,本机的mysql真的要好好调优一下了。哈哈。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,362评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,330评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,247评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,560评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,580评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,569评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,929评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,587评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,840评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,596评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,678评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,366评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,945评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,929评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,165评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,271评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,403评论 2 342