【问题标题】:How can tune MySQL for Wordpress sites?如何为 Wordpress 网站调整 MySQL?
【发布时间】:2020-02-13 23:54:18
【问题描述】:

我遇到了一个问题,即我的 MySQL 数据库运行缓慢,因此我决定与mysqltuner.pl 联系,在确定自己在做什么之前,我不想进行任何更改。

我在 Ubuntu 18.04 LTS 服务器上运行 MySQL 5.7。

这是来自 mysqltuner 的回复:

    -------- Performance Metrics -----------------------------------------------------------------------
    [--] Up for: 17h 51m 40s (400K q [6.226 qps], 15K conn, TX: 1G, RX: 63M)
    [--] Reads / Writes: 98% / 2%
    [--] Binary logging is disabled
    [--] Physical Memory     : 7.8G
    [--] Max MySQL memory    : 352.4M
    [--] Other process memory: 1.6G
    [--] Total buffers: 192.0M global + 1.1M per thread (151 max threads)
    [--] P_S Max memory usage: 72B
[OK] Maximum reached memory usage: 207.9M (2.61% of installed RAM)
[OK] Maximum possible memory usage: 352.4M (4.43% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/400K)
[OK] Highest usage of available connections: 9% (15/151)
[OK] Aborted connections: 0.01%  (1/15256)
[!!] 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.
[!!] Query cache efficiency: 0.0% (0 cached / 338K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 37K sorts)
[!!] Joins performed without indexes: 494
[!!] Temporary tables created on disk: 78% (15K on disk / 20K total)
[OK] Thread cache hit rate: 99% (30 created / 15K connections)
[OK] Table cache hit rate: 29% (1K open / 6K opened)
[OK] Open file limit used: 2% (136/5K)
[OK] Table locks acquired immediately: 100% (1K immediate / 1K locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.



-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.2% (3M used / 16M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/126.0K
[!!] Read Key buffer hit rate: 68.8% (16 cached / 5 reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 128.0M/77.4M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.96% (12403660 hits/ 12408102 total)
[!!] InnoDB Write Log efficiency: 51.81% (14419 hits/ 27833 total)
[OK] InnoDB log waits: 0.00% (0 waits / 13414 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- 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:
    Control warning line(s) into /var/log/mysql/error.log file
    Control error line(s) into /var/log/mysql/error.log file
    MySQL started within last 24 hours - recommendations may be inaccurate
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Adjust your join queries to always utilize indexes
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries which have no LIMIT clause
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 1M, or use smaller result sets)
    join_buffer_size (> 256.0K, or always use indexes with joins)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    innodb_log_file_size * innodb_log_files_in_group should be equal to 1/4 of buffer pool size (=64M) if possible.

我所有的网站都在最新版本的 Wordpress 上运行,并且大部分内容都是静态的——比如商业网站。

如何基于mysqltuneranalyze提高MySQL的性能?

【问题讨论】:

  • 附加信息请求。 # 内核,MySQL 主机服务器上的任何 SSD 或 NVME 设备?在 pastebin.com 上发布并分享链接。从 SSH 登录根,文本结果: B) SHOW GLOBAL STATUS;至少 24 小时正常运行时间后 C) 显示全局变量; D) 显示完整的处理程序; E) 完整的 MySQLTuner 报告和可选的非常有用的信息,如果可用,包括 - htop 或 top 用于大多数活动应用程序,ulimit -a 用于 Linux/Unix 限制列表,iostat -xm 5 3 用于按设备和核心/cpu 计数的 IOPS,为服务器工作负载调优分析提供建议。
  • 我们想为您提供帮助,但自 2020 年 2 月 14 日以来您还没有登录到 stackoverflow。您可以使用许多资源,但我们需要您按要求提供数据。

标签: mysql wordpress ubuntu


【解决方案1】:

你的盒子足够大,不用担心。我不知道你的磁盘驱动器有多快。如果你有 SSD,你就准备好了。如果你有一个从旧笔记本电脑上清除的驱动器,那就不是那么多了。升级吧。

您应该首先在每个 WordPress 实例的 WordPress 表上执行 OPTIMIZE TABLE。它可以帮助很多,特别是对于繁忙的网站。我已经成功使用了WP Clean Up 插件。

如果您需要做更多事情,请使用mysqldumpslow 命令找出您服务器的慢查询日志中的内容。它将识别性能最差的查询。

然后你可以在每个慢查询前加上EXPLAIN 来查看查询是如何处理的。查看查询及其 EXPLAIN 输出可以帮助您了解哪些表索引可能有助于加快处理速度。 (如何做到这一点的解释远远超出了 SO 答案的范围,但请参阅 以获取许多很好的示例。)

您能否将性能不佳的问题归结为特定插件?如果是这样,请询问插件作者。

【讨论】:

    【解决方案2】:

    从不完整的 MySQLTuner 发布报告中对您的 my.cnf [mysqld] 部分的建议,

    thread_cache_size=64
    tmp_table_size=32M
    max_heap_table_size=32M
    table_open_cache=4K
    innodb_open_files=4K  # to reduce opened_tables count
    

    请考虑发布大约 24 小时前请求的附加信息,并在关闭后完成 MySQLTuner 报告;重新启动并至少 24 小时正常工作日使用。

    【讨论】:

    • @user134969 您有机会尝试这些建议吗?请评论正面/负面结果。
    【解决方案3】:

    “元”表由 WP 实现得很差。这是我的解决方法:http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta

    另外,如果您提供 Wilson 的要求,我会检查调整。 77MB 的数据相当小,所以我不认为有太多需要改进的地方。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-10
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      相关资源
      最近更新 更多