我正在使用 whm/cpanel 升级到更快的服务器,mysql 数据库将位于 SSD 上。我读过一些关于不需要任何查询缓存和类似内容的文章,但作为新手,我了解到修改 my.cnf 可能是灾难性的。
这是我基于“硬盘”的网络服务器的当前 my.cnf。
[mysqld]
query_cache_limit=32M
query_cache_size=128M
query_cache_type=1
query_cache_min_res_unit=4096
open_files_limit=16000
table_open_cache=25000
table_definition_cache=2000
key_buffer_size=128M
innodb_buffer_pool_size=2000M
innodb_buffer_pool_instances=2
join_buffer_size=4M
sort_buffer_size=4M
read_rnd_buffer_size=4M
tmp_table_size=3048M
max_heap_table_size=3048M
thread_cache_size=256
max_connections=250
table_cache=60000
如果 mysql 在 SSD 上,您会对其进行哪些更改?
以下是来自 tuner.sh 的一些信息:
Avg. qps = 447
WORKER THREADS
Current thread_cache_size = 256
Current threads_cached = 96
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS
Current max_connections = 250
Current threads_connected = 20
Historic max_used_connections = 116
The number of used connections is 46% of the configured maximum.
Your max_connections variable seems to be fine.
INNODB STATUS
Current InnoDB index space = 794 M
Current InnoDB data space = 1.10 G
Current InnoDB buffer pool free = 14 %
Current innodb_buffer_pool_size = 1.95 G
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.62 G
Configured Max Per-thread Buffers : 3.02 G
Configured Max Global Buffers : 2.21 G
Configured Max Memory Limit : 5.23 G
Physical Memory : 15.56 G
Max memory limit seem to be within acceptable norms
KEY BUFFER
Current MyISAM index space = 222 M
Current key_buffer_size = 128 M
Key cache miss rate is 1 : 1115
Key buffer free ratio = 72 %
Your key_buffer_size seems to be fine
QUERY CACHE
Query cache is enabled
Current query_cache_size = 128 M
Current query_cache_used = 28 M
Current query_cache_limit = 32 M
Current Query cache Memory fill ratio = 22.42 %
Current query_cache_min_res_unit = 4 K
Your query_cache_size seems to be too high.
Perhaps you can use these resources elsewhere
MySQL won't cache query results that are larger than query_cache_limit in size
SORT OPERATIONS
Current sort_buffer_size = 4 M
Current read_rnd_buffer_size = 4 M
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 4.00 M
You have had 166 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
OPEN FILES LIMIT
Current open_files_limit = 120260 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 = 60000 tables
Current table_definition_cache = 2000 tables
You have a total of 733 tables
You have 851 open tables.
The table_cache value seems to be fine
TEMP TABLES
Current max_heap_table_size = 2.97 G
Current tmp_table_size = 2.97 G
Of 262494 temp tables, 33% 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 = 128 K
Current table scan ratio = 1005 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 101097
Your table locking seems to be fine
OLD 网络服务器是一个 8 核单 Xeon @ 16GB 内存。新的网络服务器是一个 24 核双至强@64GB 内存。新服务器上的 SSD 将仅包含操作系统和数据库,所有站点均基于 WordPress,因此每天的总浏览量约为 250,000 次。
非常感谢您的帮助或建议!
问候,
本
将其设置为低于 table_open_cache 没有什么意义。请参阅https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_open_files_limit中描述的默认值
考虑到您只有 < 900 个打开的表,您可能不需要将它设置得这么高。
请注意,table_cache 是 table_open_cache 的过时同义词。my.cnf 文件中的最后一个优先。因此,您已将 table_open_cache 设置为 60000,覆盖了之前的设置。我建议决定你想要的值并使用一行来设置它,以避免混淆。
这可以。
密钥缓冲区仅适用于 MyISAM。如果你没有 MyISAM 表,默认的 8M 就可以了。
如果你有很多 MyISAM 表,你应该将它们转换成 InnoDB。;-)
由于您升级到 64G,这似乎很低。另一方面,您只有大约 2G 的 InnoDB 数据和索引,这对于一个简单的 Wordpress 站点来说并不罕见。将缓冲池增加得更高没有任何好处。
从 MySQL 5.6.6 开始,BP 实例的默认数量为 8。由于您有 24 个核心,您可能希望将 BP 至少拆分为 8 个实例。
16x 默认的 256K 似乎太高了。理想情况下,您不需要依赖连接缓冲区,因为连接应该由索引处理。
在 MySQL 5.6 中,join buffer 也用于 Batched Key Access 优化,但这并不经常出现。
也是默认值 256K 的 16 倍。当您对大型表进行文件排序时,对于避免排序合并传递很有用。监控
SHOW GLOBAL STATUS LIKE 'Sort_merge_passes'
,但我敢打赌你可以减少它。也是默认值 256K 的 16 倍。用于 MyISAM 表,或用于任何存储引擎的多范围读取优化。很少需要这个。
这些恐怕都过分了。我从小开始,如果我看到
SHOW GLOBAL STATUS LIKE 'Created_tmp_disk_table'
.可能根本不需要在您的系统上有线程缓存。默认值为 33。在现代版本的 Linux 上,无论如何创建一个新线程都很快,因此对线程缓存的需求并不像在 Solaris、FreeBSD 等上那么重要。
请注意,table_cache 是 table_open_cache 的过时同义词。my.cnf 文件中的最后一个优先。因此,您已将 table_open_cache 设置为 60000,覆盖了之前的设置。我建议决定你想要的值并使用一行来设置它,以避免混淆。