我已经优化了很多次我的Mysql服务器,但现在我想要你的build议。
mysqltuner:
-------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL version 5.1.52-log [OK] Operating on 64-bit architecture -------- Storage Engine Statistics ------------------------------------------- [--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster [--] Data in MyISAM tables: 26G (Tables: 36) [--] Data in InnoDB tables: 221M (Tables: 35) [!!] Total fragmented tables: 41 -------- Security Recommendations ------------------------------------------- [!!] User '@localhost' has no password set. -------- Performance Metrics ------------------------------------------------- [--] Up for: 78d 11h 57m 53s (1B q [151.485 qps], 1M conn, TX: 336B, RX: 218B) [--] Reads / Writes: 60% / 40% [--] Total buffers: 2.2G global + 8.2M per thread (300 max threads) [OK] Maximum possible memory usage: 4.6G (39% of installed RAM) [OK] Slow queries: 0% (55K/1B) [OK] Highest usage of available connections: 69% (209/300) [OK] Key buffer size / total MyISAM indexes: 2.0G/6.1G [OK] Key buffer hit rate: 98.2% (2B cached / 47M reads) [OK] Query cache efficiency: 28.9% (79M cached / 276M selects) [!!] Query cache prunes per day: 102031 [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 3M sorts) [OK] Temporary tables created on disk: 25% (1M on disk / 3M total) [OK] Thread cache hit rate: 98% (16K created / 1M connections) [!!] Table cache hit rate: 7% (330 open / 4K opened) [OK] Open file limit used: 14% (149/1K) [OK] Table locks acquired immediately: 99% (489M immediate / 490M locks) [!!] InnoDB data size / buffer pool: 221.3M/128.0M -------- Recommendations ----------------------------------------------------- General recommendations: Run OPTIMIZE TABLE to defragment tables for better performance Increase table_cache gradually to avoid file descriptor limits Variables to adjust: query_cache_size (> 20M) table_cache (> 400) innodb_buffer_pool_size (>= 221M)
调整底漆:
SLOW QUERIES The slow query log is enabled. Current long_query_time = 1.000000 sec. You have 56239 out of 1027500028 that take longer than 1.000000 sec. to complete Your long_query_time seems to be fine BINARY UPDATE LOG The binary update log is enabled Binlog sync is not enabled, you could loose binlog records during a server crash WORKER THREADS Current thread_cache_size = 10 Current threads_cached = 7 Current threads_per_sec = 0 Historic threads_per_sec = 0 Your thread_cache_size is fine MAX CONNECTIONS Current max_connections = 300 Current threads_connected = 26 Historic max_used_connections = 209 The number of used connections is 69% of the configured maximum. Your max_connections variable seems to be fine. INNODB STATUS Current InnoDB index space = 28 M Current InnoDB data space = 221 M Current InnoDB buffer pool free = 0 % Current innodb_buffer_pool_size = 128 M Depending on how much space your innodb indexes take up it may be safe to increase this value to up to 2 / 3 of total system memory MEMORY USAGE Max Memory Ever Allocated : 3.78 G Configured Max Per-thread Buffers : 2.42 G Configured Max Global Buffers : 2.09 G Configured Max Memory Limit : 4.52 G Physical Memory : 11.73 G Max memory limit seem to be within acceptable norms KEY BUFFER Current MyISAM index space = 6.09 G Current key_buffer_size = 1.95 G Key cache miss rate is 1 : 54 Key buffer free ratio = 0 % You could increase key_buffer_size It is safe to raise this up to 1/4 of total system memory; assuming this is a dedicated database server. QUERY CACHE Query cache is enabled Current query_cache_size = 20 M Current query_cache_used = 6 M Current query_cache_limit = 4 M Current Query cache Memory fill ratio = 33.45 % Current query_cache_min_res_unit = 4 K Query Cache is 30 % fragmented Run "FLUSH QUERY CACHE" periodically to defragment the query cache memory If you have many small queries lower 'query_cache_min_res_unit' to reduce fragmentation. MySQL won't cache query results that are larger than query_cache_limit in size SORT OPERATIONS Current sort_buffer_size = 2 M Current read_rnd_buffer_size = 2 M Sort buffer seems to be fine JOINS Current join_buffer_size = 2.00 M You have had 12284 queries where a join could not use an index properly You should enable "log-queries-not-using-indexes" Then look for non indexed joins in the slow query log. If you are unable to optimize your queries you may want to increase your join_buffer_size to accommodate larger joins in one pass. Note! This script will still suggest raising the join_buffer_size when ANY joins not using indexes are found. OPEN FILES LIMIT Current open_files_limit = 1024 files The open_files_limit should typically be set to at least 2x-3x that of table_cache if you have heavy MyISAM usage. Your open_files_limit value seems to be fine TABLE CACHE Current table_open_cache = 400 tables Current table_definition_cache = 256 tables You have a total of 94 tables You have 330 open tables. The table_cache value seems to be fine TEMP TABLES Current max_heap_table_size = 128 M Current tmp_table_size = 128 M Of 2988791 temp tables, 25% were created on disk Perhaps you should increase your tmp_table_size and/or max_heap_table_size to reduce the number of disk-based temporary tables Note! BLOB and TEXT columns are not allow in memory tables. If you are using these columns raising these values might not impact your ratio of on disk temp tables. TABLE SCANS Current read_buffer_size = 2 M Current table scan ratio = 5 : 1 read_buffer_size seems to be fine TABLE LOCKING Current Lock Wait ratio = 1 : 5129 Your table locking seems to be fine
和记忆信息:
[air@prod01 ~]$ free -m total used free shared buffers cached Mem: 12011 11926 85 0 406 6395 -/+ buffers/cache: 5123 6887 Swap: 1027 0 1027
查询资讯:
mysql> show status like "Qc_%"; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | Qcache_free_blocks | 3447 | | Qcache_free_memory | 13968768 | | Qcache_hits | 79867788 | | Qcache_inserts | 163036705 | | Qcache_lowmem_prunes | 8012726 | | Qcache_not_cached | 33127499 | | Qcache_queries_in_cache | 3758 | | Qcache_total_blocks | 11259 | +-------------------------+-----------+
我已经增加了table_open_cache值在330到400。
我应该做些什么来获得更好的表演吗?
谢谢
你应该做的第一步是安装一些性能graphics软件,并开始使用它来绘制你的服务器的重要统计数据。
其中一个将做这项工作: 更好的仙人掌模板或阿帕卢卡Zabbix模板
一旦到位,你可以看到你的正常工作量是什么样子,然后开始改变价值观,看看他们做了什么差异。
如果你不衡量你的performance,你所做的任何改变都只是猜测而已。
我在MyISAM上完成了大部分优化(大多数我的数据库的写入less于3%)。但是,我有一些一般的MySQL优化供您考虑。 按照优先顺序,关于你的情况。
考虑到你只有71桌,这是非常高的。 有这样一个很重要的比例写道,在你的情况下,它解释了原因。 我会优化所有的数据库。 这在MyISAM表中是最有效的,但是它们组成了大部分的数据。 不要中途停止这个命令!
mysqlcheck --all-databases --optimize
这是过度的,几乎可以解释为什么你的查询caching效率可能会更好。 按照mysqltuner的build议,把那20M提高到64M以上。 (如果这太过分了,你可以降低它,但最终可能会过于保守)在mysqld部分的my.cnf中查找这行,将你的20M更改为64M
query_cache_size = 64M
你想要一个比表数据大10%的缓冲池。 所以更像245,但我真的去250(使它,甚至给一些房间)改变你的生产线从221M到250M。
innodb_buffer_pool_size = 250M
这就是我可以安全地推荐没有更多的信息,我想你也需要提高table_cache。 我不确定最好是什么,你会想在一段时间内检查你打开的桌子。
还要确保你写的重度表使用的是InnoDB,重读我会去MyISAM。 有些应用程序只使用InnoDB的function,这是应该考虑的。 有些人会因为不同的原因一直在争论一个引擎或者另一个引擎。 这就是我会做的。