MySQL优化 - 需要建议

时间:2015-07-08 08:35:59

标签: mysql optimization

我有一台拥有32 GB RAM(4核/ 8线程)3.4 GHz +的CentOS 7 VM 我运行了MySQLTuner脚本,并按照他们给出的建议,但它仍然很慢

我在my.cnf文件中的当前配置是:

[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

key_buffer        = 32M
max_allowed_packet    = 268435456
thread_stack        = 192K
thread_cache_size       = 384
key_buffer_size=32G
max_connections = 1200
max_user_connections=1000
table_open_cache=3000
table_open_cache=5000
table_definition_cache=2048
sort_buffer_size=32M
join_buffer_size = 32M
read_buffer_size=32M
wait_timeout=20
read_rnd_buffer_size=786432
bulk_insert_buffer_size = 8M

myisam_sort_buffer_size=64M
query_cache_size=128M
query_cache_limit=8M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65535
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 8
tmp_table_size=320M
thread_concurrency=32


innodb_lock_wait_timeout = 600
innodb_additional_mem_pool_size=60M
innodb_buffer_pool_size=20G
innodb_buffer_pool_instances=20
innodb_table_locks=0
max_heap_table_size=128M
net_buffer_length = 16384
max_connect_errors = 10
open_files_limit=50000
default-storage-engine=InnoDB
low-priority-updates=1
innodb_file_per_table=1
concurrent_insert=ALWAYS


[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d










[myisamchk]
key_buffer_size=512M
sort_buffer_size=256M
read_buffer=256M
write_buffer=256M


[mysqldump]
quick
quote-names
max_allowed_packet    = 16M



[isamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M

我不久前重启了MySQL,以应用我最近的更改。

当我运行脚本时,这就是我得到的:

 >>  MySQLTuner 1.4.4 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
[[0;32mOK[0m] Currently running supported MySQL version 5.5.41-MariaDB
[[0;32mOK[0m] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[[0;34m--[0m] Status: [0;32m+ARCHIVE [0m[0;32m+Aria [0m[0;32m+BLACKHOLE [0m[0;32m+CSV [0m[0;32m+FEDERATED [0m[0;32m+InnoDB [0m[0;32m+MRG_MYISAM [0m
[[0;34m--[0m] Data in MyISAM tables: 23M (Tables: 75)
[[0;34m--[0m] Data in InnoDB tables: 65M (Tables: 643)
[[0;34m--[0m] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[[0;34m--[0m] Data in MEMORY tables: 0B (Tables: 4)
[[0;31m!![0m] Total fragmented tables: 516

-------- Security Recommendations  -------------------------------------------
[[0;32mOK[0m] There is no anonymous account in all database users
[[0;32mOK[0m] All database users have passwords assigned
[[0;31m!![0m] User 'pixoneo@%' hasn't specific host restriction.
[[0;34m--[0m] There is 605 basic passwords in the list.

-------- Performance Metrics -------------------------------------------------
[[0;34m--[0m] Up for: 20m 58s (877K q [697.220 qps], 52K conn, TX: 16B, RX: 195M)
[[0;34m--[0m] Reads / Writes: 96% / 4%
[[0;34m--[0m] Total buffers: 22.3G global + 4.9M per thread (1200 max threads)
[[0;31m!![0m] Maximum possible memory usage: 28.1G (89% of installed RAM)
[[0;32mOK[0m] Slow queries: 0% (9/877K)
[[0;32mOK[0m] Highest usage of available connections: 40% (483/1200)
[[0;32mOK[0m] Key buffer size / total MyISAM indexes: 2.0G/773.0K
[[0;31m!![0m] Key buffer hit rate: 94.3% (53 cached / 3 reads)
[[0;32mOK[0m] Query cache efficiency: 45.6% (497K cached / 1M selects)
[[0;32mOK[0m] Query cache prunes per day: 0
[[0;32mOK[0m] Sorts requiring temporary tables: 0% (0 temp sorts / 22K sorts)
[[0;31m!![0m] Joins performed without indexes: 15817
[[0;32mOK[0m] Temporary tables created on disk: 11% (23K on disk / 204K total)
[[0;32mOK[0m] Thread cache hit rate: 99% (483 created / 52K connections)
[[0;32mOK[0m] Table cache hit rate: 102% (1K open / 1K opened)
[[0;32mOK[0m] Open file limit used: 23% (239/1K)
[[0;32mOK[0m] Table locks acquired immediately: 100% (199K immediate / 199K locks)

-------- InnoDB Metrics -----------------------------------------------------
[[0;34m--[0m] InnoDB is enabled.
[[0;34m--[0m] InnoDB BufferPool Size :20.0G
[[0;34m--[0m] InnoDB BufferPool Inst :1
[[0;32mOK[0m] InnoDB buffer pool / data size: 20.0G/65.4M
[[0;31m!![0m] InnoDB buffer pool instances: 1
[[0;32mOK[0m] InnoDB log waits: 0

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Restrict Host for user@% to user@SpecificDNSorIp
    MySQL started within last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Enable the slow query log to troubleshoot bad queries
    Adjust your join queries to always utilize indexes
Variables to adjust:
    join_buffer_size (> 1.0M, or always use indexes with joins)
    innodb_buffer_pool_instances(=20)

有没有人对现在该做什么有任何建议?谢谢

1 个答案:

答案 0 :(得分:1)

  

的key_buffer_size = 32G

NO!你没有留下任何其他空间。你在使用MyISAM吗?如果是这样,请将其设置为适用于32GB服务器的4G。如果没有,请将其设置为20M。

  

密钥缓冲区大小/总MyISAM索引:2.0G / 773.0K

这是矛盾的!它是2G还是32G?做Max_used_connections = 483。如果它说2G,那么你没有向我们展示正在使用的my.cnf。

  

总碎片表:516

忽略;大多数表都是“碎片化的”#34;大多数时候。它不值得担心。

在20分钟内查询877K?那很忙。如果打开慢速日志,请查看其中显示的内容。

483/1200个连接。他们忘了断开连接吗?还有什么可能导致long_query_time=1

  

线程缓存命中率:99%(创建483个/ 52K连接)
  table_open_cache = 5000

5000是矫枉过正

无论如何,真正要注意的是&#34;慢&#34;是 SlowLog

  • 设置pt-query-digest
  • 开启慢速日志
  • 等一天
  • 使用SHOW CREATE TABLE汇总慢速日志
  • 向我们展示该摘要中的前几个查询
  • 包括EXPLAIN SELECT ...和{{1}}用于这些表格和查询