sql >> データベース >  >> RDS >> Mysql

MySQLTunnerツールを使用してMySQL/MariaDBのパフォーマンスを最適化する

    MySQLTunnerは、MariaDB/MySQLデータベースサーバーの調整を支援するPerlツールです。サーバーの多くのパラメーターをチェックし、ユーザーパスワードを検証し、匿名ユーザー、安全でないパスワード(たとえば、パスワードはユーザー名)をチェックし、既知のCVEの脆弱性をチェックします。

    ツールを実行する最初のステップは、公式Webサイトhttps://github.com/major/MySQLTuner-perl

    からスクリプトファイルをダウンロードすることです。
    wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
    wget https://github.com/major/MySQLTuner-perl/raw/master/vulnerabilities.csv

    スクリプトを実行するための基本的なコマンドは次のとおりです。

    perl mysqltuner.pl

    脆弱性も確認するには、vulnerabilities.csvファイルをダウンロードして、次のコマンドを実行する必要があります。

    perl mysqltuner.pl --cvefile=vulnerabilities.csv

    テストサーバーからの出力の例:

    [root@web /]# perl mysqltuner.pl --cvefile=vulnerabilities.csv
    
     >>  MySQLTuner 1.8.7 - Major Hayden <[email protected]>
     >>  Bug reports, feature requests, and downloads at http://mysqltuner.pl/
     >>  Run with '--help' for additional options and output filtering
    
    [--] Skipped version check for MySQLTuner script
    [OK] Currently running supported MySQL version 10.6.5-MariaDB
    [OK] Operating on 64-bit architecture
    
    -------- Log file Recommendations ------------------------------------------------------------------
    [OK] Log file /var/log/mysqld.log exists
    [--] Log file: /var/log/mysqld.log(69K)
    [OK] Log file /var/log/mysqld.log is not empty
    [OK] Log file /var/log/mysqld.log is smaller than 32 Mb
    [OK] Log file /var/log/mysqld.log is readable.
    [!!] /var/log/mysqld.log contains 394 warning(s).
    [!!] /var/log/mysqld.log contains 49 error(s).
    [--] 22 start(s) detected in /var/log/mysqld.log
    [--] 1) 2022-01-08 16:04:41 0 [Note] /usr/sbin/mysqld: ready for connections.
    [--] 2) 2022-01-04 12:20:12 0 [Note] /usr/sbin/mysqld: ready for connections.
    [--] 3) 2021-12-27 17:21:20 0 [Note] /usr/sbin/mysqld: ready for connections.
    [--] 4) 2021-12-11 15:39:01 0 [Note] /usr/sbin/mysqld: ready for connections.
    [--] 5) 2021-12-11 14:47:28 0 [Note] /usr/sbin/mysqld: ready for connections.
    [--] 6) 2021-12-11 14:47:22 0 [Note] /usr/sbin/mysqld: ready for connections.
    -------- Storage Engine Statistics -----------------------------------------------------------------
    [--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
    [--] Data in Aria tables: 32.0K (Tables: 1)
    [--] Data in MEMORY tables: 0B (Tables: 40)
    [--] Data in MyISAM tables: 1.3G (Tables: 34)
    [--] Data in InnoDB tables: 217.2M (Tables: 31)
    [OK] Total fragmented tables: 0
    
    -------- Analysis Performance Metrics --------------------------------------------------------------
    [--] innodb_stats_on_metadata: OFF
    [OK] No stat updates during querying INFORMATION_SCHEMA.
    
    -------- Views Metrics -----------------------------------------------------------------------------
    
    -------- Triggers Metrics --------------------------------------------------------------------------
    
    -------- Routines Metrics --------------------------------------------------------------------------
    
    -------- Security Recommendations ------------------------------------------------------------------
    [OK] All database users have passwords assigned
    -------- CVE Security Recommendations --------------------------------------------------------------
    [OK] NO SECURITY CVE FOUND FOR YOUR VERSION
    
    -------- Performance Metrics -----------------------------------------------------------------------
    [--] Up for: 4d 19h 31m 2s (18M q [45.289 qps], 550K conn, TX: 53G, RX: 3G)
    [--] Reads / Writes: 90% / 10%
    [--] Binary logging is disabled
    [--] Physical Memory     : 4.0G
    [--] Max MySQL memory    : 38.3G
    [--] Other process memory: 0B
    [--] Total buffers: 305.0M global + 259.7M per thread (150 max threads)
    [--] P_S Max memory usage: 0B
    [--] Galera GCache Max memory usage: 0B
    [OK] Slow queries: 0% (33/18M)
    [OK] Highest usage of available connections: 76% (114/150)
    [OK] Aborted connections: 0.02%  (86/550353)
    [!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
    [OK] Query cache is disabled by default due to mutex contention on multiprocessor machines.
    [OK] Sorts requiring temporary tables: 0% (227 temp sorts / 3M sorts)
    [!!] Joins performed without indexes: 197183
    [!!] Temporary tables created on disk: 56% (990K on disk / 1M total)
    [OK] Thread cache hit rate: 99% (645 created / 550K connections)
    [OK] Table cache hit rate: 95% (22M hits / 24M requests)
    [OK] Open file limit used: 8% (1K/16K)
    [OK] Table locks acquired immediately: 99% (17M immediate / 17M locks)
    
    -------- Performance schema ------------------------------------------------------------------------
    [--] Performance schema is disabled.
    [--] Memory used by P_S: 0B
    [--] Sys schema is installed.
    
    -------- ThreadPool Metrics ------------------------------------------------------------------------
    [--] ThreadPool stat is enabled.
    [--] Thread Pool Size: 2 thread(s).
    [--] Using default value is good enough for your version (10.6.5-MariaDB)
    
    -------- MyISAM Metrics ----------------------------------------------------------------------------
    [!!] Key buffer used: 61.8% (9.9M used / 16.0M cache)
    [OK] Key buffer size / total MyISAM indexes: 16.0M/152.4M
    [OK] Read Key buffer hit rate: 100.0% (768M cached / 379K reads)
    [!!] Write Key buffer hit rate: 54.4% (3M cached / 1M writes)
    
    -------- InnoDB Metrics ----------------------------------------------------------------------------
    [--] InnoDB is enabled.
    [OK] InnoDB File per table is activated
    [!!] InnoDB buffer pool / data size: 128.0M/217.2M
    [!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 96.0M * 1/128.0M should be equal to 25%
    [--] 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.98% (499634018 hits/ 499732161 total)
    [!!] InnoDB Write Log efficiency: 270.94% (232636 hits/ 85863 total)
    [OK] InnoDB log waits: 0.00% (0 waits / 318499 writes)
    
    -------- Aria Metrics ------------------------------------------------------------------------------
    [--] Aria Storage Engine is enabled.
    [OK] Aria pagecache size / total Aria indexes: 128.0M/712.0K
    [OK] Aria pagecache hit rate: 95.4% (18M cached / 860K 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:
        Check warning line(s) in /var/log/mysqld.log file
        Check error line(s) in /var/log/mysqld.log file
        Reduce your overall MySQL memory footprint for system stability
        Dedicate this server to your database for highest performance.
        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
        Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
    Variables to adjust:
      *** MySQL's maximum memory usage is dangerously high ***
      *** Add RAM before increasing MySQL buffer variables ***
        join_buffer_size (> 1.0M, or always use indexes with JOINs)
        tmp_table_size (> 16M)
        max_heap_table_size (> 16M)
        performance_schema = ON enable PFS
        key_buffer_size (~ 10M)
    

    推奨事項を注意深く確認してください セクションを作成し、必要なアクションを実行します。 MySQL / MariaDBオプションは、/ etc/my.cnfファイルに保存されます。このファイルは、viやnanoなどのエディターで編集できます:

    nano /etc/my.cnf

    最後に、ファイルを保存してMySQLサーバーを再起動します。

    service mysqld restart

    1. テーブル式の基礎、パート9 –ビュー、派生テーブルおよびCTEとの比較

    2. .csvファイルをOracleFormsアプリケーションにインポートする

    3. PostgreSQLでのAtanh()のしくみ

    4. 行の値をCSVにマージします(SQL Serverの場合はGROUP_CONCATとも呼ばれます)