为 wordpress 优化 MariaDB
Optimizing MariaDB for wordpress
我的服务器有 2 CPU 个内核和 1GB 的 RAM.The 服务器 运行 一个 wordpress site.My 服务器堆栈是 LEMP.I 运行 mysql 设置 wordpress 网站两周后调谐器。
这是结果
[!!] Maximum reached memory usage: 884.8M (89.15% of installed RAM)
[!!] Maximum possible memory usage: 1.4G (139.86% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[!!] Slow queries: 15% (629K/4M)
[OK] Highest usage of available connections: 9% (19/200)
[OK] Aborted connections: 0.75% (4103/548857)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
这是我的my.cnf
配置
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid-file = /var/lib/mysql/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /var/lib/mysql/
# BINARY LOGGING #
log-bin = /var/lib/mysql/mysql-bin
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 200
thread-cache-size = 20
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 624M
# LOGGING #
log-error = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
我如何优化配置以解决这些问题
有一个非常糟糕的设置:
innodb-buffer-pool-size = 624M
在可能同时包含 WP 和 MySQL 的小型 1GB 服务器中?将其更改为 200M。并注意交换。如果有任何交换,则将其降低更多。交换导致大量 I/O;最好缩小设置。这是一个良好的开端:
tmp-table-size = 32M -> 8M
max-heap-table-size = 32M -> 8M
query-cache-type = 0 -- good
query-cache-size = 0 -- good
max-connections = 200 -> 50
thread-cache-size = 20
open-files-limit = 65535
table-definition-cache = 1024 -> 200
table-open-cache = 2048 -> 300
你开启了慢速日志?让我们看看最差的查询,如 mysqldumpslow -s t
或 pt-query-digest
.
所示
这是另一个提示。这个重要的 table 目前有糟糕的索引;这些会有所帮助:
CREATE TABLE wp_postmeta (
post_id …,
meta_key …,
meta_value …,
PRIMARY KEY(post_id, meta_key),
INDEX(meta_key)
) ENGINE=InnoDB;
WORDPRESS 正在收听吗?
原因如下:
AUTO_INCREMENT
太浪费了
- 这个PK好多了
- 必要时使用 191(5.6.3 至 5.7.6)
- 用于集群 PK 的 InnoDB
更多详情: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta
我的服务器有 2 CPU 个内核和 1GB 的 RAM.The 服务器 运行 一个 wordpress site.My 服务器堆栈是 LEMP.I 运行 mysql 设置 wordpress 网站两周后调谐器。 这是结果
[!!] Maximum reached memory usage: 884.8M (89.15% of installed RAM)
[!!] Maximum possible memory usage: 1.4G (139.86% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[!!] Slow queries: 15% (629K/4M)
[OK] Highest usage of available connections: 9% (19/200)
[OK] Aborted connections: 0.75% (4103/548857)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
这是我的my.cnf
配置
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid-file = /var/lib/mysql/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /var/lib/mysql/
# BINARY LOGGING #
log-bin = /var/lib/mysql/mysql-bin
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 200
thread-cache-size = 20
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 624M
# LOGGING #
log-error = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
我如何优化配置以解决这些问题
有一个非常糟糕的设置:
innodb-buffer-pool-size = 624M
在可能同时包含 WP 和 MySQL 的小型 1GB 服务器中?将其更改为 200M。并注意交换。如果有任何交换,则将其降低更多。交换导致大量 I/O;最好缩小设置。这是一个良好的开端:
tmp-table-size = 32M -> 8M
max-heap-table-size = 32M -> 8M
query-cache-type = 0 -- good
query-cache-size = 0 -- good
max-connections = 200 -> 50
thread-cache-size = 20
open-files-limit = 65535
table-definition-cache = 1024 -> 200
table-open-cache = 2048 -> 300
你开启了慢速日志?让我们看看最差的查询,如 mysqldumpslow -s t
或 pt-query-digest
.
这是另一个提示。这个重要的 table 目前有糟糕的索引;这些会有所帮助:
CREATE TABLE wp_postmeta (
post_id …,
meta_key …,
meta_value …,
PRIMARY KEY(post_id, meta_key),
INDEX(meta_key)
) ENGINE=InnoDB;
WORDPRESS 正在收听吗?
原因如下:
AUTO_INCREMENT
太浪费了- 这个PK好多了
- 必要时使用 191(5.6.3 至 5.7.6)
- 用于集群 PK 的 InnoDB
更多详情: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta