gpt4 book ai didi

mysql - 如何使用 MySQLTuner 正确配置 MySQL

转载 作者:行者123 更新时间:2023-11-30 21:51:35 25 4
gpt4 key购买 nike

我是新手,我刚刚安装了我的第一台服务器,我正在使用 MySQLTuner 来优化 MySQL 数据库,但我不知道根据 MySQLTuner 的输出调整什么是更好的方法。如何根据 MySQLTuner 输出调优 my.cnf

这是 MySQLTuner 的输出:

 >>  MySQLTuner 1.7.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

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from debian maintenance account.
[OK] Currently running supported MySQL version 10.1.28-MariaDB-1~trusty
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /var/lib/mysql/s118874.err(0B)
[!!] Log file /var/lib/mysql/s118874.err doesn't exist
[!!] Log file /var/lib/mysql/s118874.err isn't readable.

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in MyISAM tables: 1G (Tables: 53)
[--] Data in InnoDB tables: 2G (Tables: 502)
[OK] Total fragmented tables: 0

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 1d 13h 39m 11s (9M q [73.549 qps], 390K conn, TX: 13G, RX: 1G)
[--] Reads / Writes: 93% / 7%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory : 23.5G
[--] Max MySQL memory : 4.1G
[--] Other process memory: 12.1G
[--] Total buffers: 2.6G global + 7.5M per thread (200 max threads)
[--] P_S Max memory usage: 98M
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 4.1G (17.61% of installed RAM)
[OK] Maximum possible memory usage: 4.1G (17.61% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/9M)
[!!] Highest connection usage: 100% (200/200)
[OK] Aborted connections: 0.00% (0/390176)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[OK] Query cache efficiency: 27.0% (2M cached / 9M selects)
[!!] Query cache prunes per day: 406250
[OK] Sorts requiring temporary tables: 0% (452 temp sorts / 1M sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 31% (505K on disk / 1M total)
[OK] Thread cache hit rate: 99% (346 created / 390K connections)
[!!] Table cache hit rate: 4% (400 open / 9K opened)
[OK] Open file limit used: 7% (77/1K)
[OK] Table locks acquired immediately: 99% (7M immediate / 7M locks)
[OK] Binlog cache memory access: 100.00% (501178 Memory / 501178 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 98.8M
[--] Sys schema isn't installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 16 thread(s).
[--] Using default value is good enough for your version (10.1.28-MariaDB-1~trusty)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 29.4% (39M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/150.6M
[OK] Read Key buffer hit rate: 100.0% (2B cached / 38K reads)
[OK] Write Key buffer hit rate: 99.3% (48K cached / 48K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 2.0G/2.0G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (3.125 %): 32.0M * 2/2.0G should be equal 25%
[!!] InnoDB buffer pool instances: 8
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 100.00% (1820526478 hits/ 1820563369 total)
[!!] InnoDB Write Log efficiency: 5.26% (27496 hits/ 522990 total)
[OK] InnoDB log waits: 0.00% (0 waits / 550486 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[OK] Aria pagecache hit rate: 97.8% (22M cached / 478K reads)

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.

-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.

-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Reduce or eliminate persistent connections to reduce connection usage
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
Increasing the query_cache size over 128M may reduce performance
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Increase table_open_cache gradually to avoid file descriptor limits

Beware that open_files_limit (1024) variable
should be greater than table_open_cache (400)
Consider installing Sys schema from https://github.com/mysql/mysql-sys

Variables to adjust:
max_connections (> 200)
wait_timeout (< 300)
interactive_timeout (< 28800)
query_cache_size (=0)
query_cache_type (=0)
query_cache_size (> 256M) [see warning above]
tmp_table_size (> 64M)
max_heap_table_size (> 64M)
table_open_cache (> 400)
innodb_buffer_pool_size (>= 2G) if possible.
innodb_log_file_size should be (=256M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
innodb_buffer_pool_instances(=2)

我当前在 MySQL 上的设置:

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
skip-external-locking
bind-address = 127.0.0.1

max_connections = 200
connect_timeout = 5
wait_timeout = 300
max_allowed_packet = 16M
thread_cache_size = 128
sort_buffer_size = 4M
bulk_insert_buffer_size = 16M
tmp_table_size = 64M
max_heap_table_size = 64M
performance_schema = ON

myisam_recover_options = BACKUP
key_buffer_size = 128M
#open-files-limit = 2000
table_open_cache = 400
myisam_sort_buffer_size = 512M
concurrent_insert = 2
read_buffer_size = 2M
read_rnd_buffer_size = 1M

query_cache_limit = 2G
query_cache_size = 256M
#query_cache_strip_comments =1
query_cache_type = 1
log_warnings = 2
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit = 1000
log_slow_verbosity = query_plan

#log-queries-not-using-indexes
#log_slow_admin_statements

#server-id = 1
#report_host = master1
#auto_increment_increment = 2
#auto_increment_offset = 1
log_bin = /var/log/mysql/mariadb-bin
log_bin_index = /var/log/mysql/mariadb-bin.index
# not fab for performance, but safer
#sync_binlog = 1
expire_logs_days = 10
max_binlog_size = 100M
# slaves
#relay_log = /var/log/mysql/relay-bin
#relay_log_index = /var/log/mysql/relay-bin.index
#relay_log_info_file = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only

#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
default_storage_engine = InnoDB
innodb_log_file_size = 32M
innodb_buffer_pool_size = 2G
innodb_log_buffer_size = 8M
innodb_file_per_table = 1
innodb_open_files = 400
innodb_io_capacity = 400
innodb_flush_method = O_DIRECT

# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completion

[isamchk]
key_buffer = 16M

!includedir /etc/mysql/conf.d/

free -m 输出

             total       used       free     shared    buffers     cached
Mem: 24102 21972 2129 65 441 12206
-/+ buffers/cache: 9324 14777
Swap: 87 0 87

htop

htop screen capture

最佳答案

以下建议需要您在每天实现一项之前进行研究。有些可以动态应用。建议的 cfg/ini 值如下,可以修改、添加或删除。

read_buffer_size  REMOVE to allow Default of 128K to work for you
read_rnd_buffer_size REMOVE to allow Default of 256K to work for you
query_cache_limit=256M # from 2G one query result can not be > query_cache_size
query_cache_size=2G # from 256M MySQLTuner recommends against. You may know your goals better.
thread_cache_size=100 # from 128 CAP recommend at this time for V8
table_open_cache=10000 # from 400 to support 9K opened since start
open_files_limit=20000 # from 1024 ulimit will need to be raised
innodb_buffer_pool_size=4G # from 2G because change buffer 25% is reserved

在您的第一个服务器安装中表现出色。在适当的时候,请提供反馈,接受。

关于mysql - 如何使用 MySQLTuner 正确配置 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46985436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com