mysql - MariaDB 的最佳配置是什么? (CentOS 8、MariaDB 10.5)

标签 mysql mariadb my.cnf cpu mysqltuner

您好,我在 Centos 8 上有 MariaDB 10.5 服务器配置 18 核 32 线程和 32GB 内存

我有足够的可用内存,但我正在尝试针对 CPU 进行优化 更少的 CPU 工作和更多的内存使用

我如何在 my.cnf 中做到这一点?

而且我不知道应该在哪里添加此更改到/etc/my.cnf 或/etc/my.cnf.d/server.cnf

我听说增加 innodb_buffer_pool_size 会有所帮助,因为我有足够的内存,但我不知道如何做到这一点,特别是在 mariadb 10.5 上如何操作。

请帮忙。

这里是 mysql tunner

 >>  MySQLTuner 1.7.19 - 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
[!!] Successfully authenticated with no password - SECURITY RISK!
[!!] Your MySQL version 10.5.0-MariaDB is EOL software!  Upgrade soon!
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[!!] Log file  doesn't exist

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

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- 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: 17m 33s (333K q [316.542 qps], 855 conn, TX: 1G, RX: 36M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is disabled
[--] Physical Memory     : 31.2G
[--] Max MySQL memory    : 3.2G
[--] Other process memory: 0B
[--] Total buffers: 417.0M global + 18.9M per thread (151 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 587.2M (1.84% of installed RAM)
[OK] Maximum possible memory usage: 3.2G (10.24% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/333K)
[OK] Highest usage of available connections: 5% (9/151)
[OK] Aborted connections: 0.00%  (0/855)
[!!] 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 / 325K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (1 temp sorts / 15K sorts)
[!!] Joins performed without indexes: 6
[!!] Temporary tables created on disk: 82% (4K on disk / 5K total)
[OK] Thread cache hit rate: 98% (9 created / 855 connections)
[OK] Table cache hit rate: 94% (94 open / 100 opened)
[OK] table_definition_cache(400) is upper than number of tables(391)
[OK] Open file limit used: 0% (30/4K)
[OK] Table locks acquired immediately: 100% (119 immediate / 119 locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema isn't installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 32 thread(s).
[--] Using default value is good enough for your version (10.5.0-MariaDB)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.2% (24M used / 134M cache)
[!!] Cannot calculate MyISAM index size - re-run script as root user

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 128.0M/4.4G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 96.0M * 1/128.0M should be equal to 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: 95.74% (313581438 hits/ 327537414 total)
[!!] InnoDB Write Log efficiency: 3.28% (92 hits/ 2808 total)
[OK] InnoDB log waits: 0.00% (0 waits / 2900 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/320.0K
[OK] Aria pagecache hit rate: 98.5% (273K cached / 4K reads)

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

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

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

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: OFF
[--] Semi synchronous replication Slave: OFF
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    We will suggest raising the 'join_buffer_size' until JOINs not using indexes are found.
             See https://dev.mysql.com/doc/internals/en/join-buffer-size.html
             (specially the conclusions at the bottom of the page).
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries which have no LIMIT clause
    Performance schema should be activated for better diagnostics
    Consider installing Sys schema from https://github.com/mysql/mysql-sys for MySQL
    Consider installing Sys schema from https://github.com/FromDual/mariadb-sys for MariaDB
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
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)
    performance_schema = ON enable PFS
    innodb_buffer_pool_size (>= 4.4G) if possible.
    innodb_log_file_size should be (=32M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

最佳答案

如果您刚刚开始使用 MariaDB,那么您的问题还为时过早。对于小型、随意的使用,MariaDB 可以“开箱即用”地正常工作。

对于专用于 MySQL/MariaDB 的服务器上的 32GB RAM,请设置

innodb_buffer_pool_size = 24G

/etc/my.cnf 是否已经存在?看它。如果已有设置,则更改它。如果没有,该文件中是否有“includedir”?

如果您在同一台计算机上运行其他应用程序,请减少该应用程序以为它们腾出空间。不允许发生交换。

在出现问题之前,其他一切都可以保留。也就是说,不存在“魔法”。

但是,如果您担心 CPU 使用情况,请注意“慢”查询并解决它们。调整查询,而不是调整,是为了获得高 CPU 或平均负载。

有关用于此目的的 SlowLog 的更多信息:http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog

关于mysql - MariaDB 的最佳配置是什么? (CentOS 8、MariaDB 10.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59726027/

相关文章:

mysql - 在mysql中运行多个mysql实例

php - 根据用户输入从数据库中选择数据

Mysql 使用 CHAR 或 BLOB 存储已知字节大小限制的 UTF-8 字符串

mysql - 保持数据与异步 HTTP 请求一致

MySQL 不喜欢 ~/.my.cnf 中的任何配置

mysql - MAMP MySQL 无法识别 OSX 中的 my.cnf 值

mysql - SQL创建矩阵表

php - 如何将一行的主键插入到它的另一列中?

mysql - 如何选择仅存在于数据条目范围之间的值?

mysql - LOCK TABLES 表示表未锁定后在 UNION 查询上进行 SELECT