Optimize MySQL server
Running MySQL at most possible optimal settings for specific resources, is a must if you want to keep your server load low and prevent slowdown of the entire server.
Here we will cover only the basics of editing your MySQL configuration on Linux CentOS server.
Tools That Can Help Optimize MySQL
The first step before anything else, is to determine if your MySQL server needs to be reconfigured and in order to do that you need to understand how your resources are performing now, this can be done with the top utility.
MySQLTuner
The MySQLTuner script assesses your MySQL installation, and then outputs suggestions for increasing your server’s performance and stability.
Download MySQLTuner:
curl -L http://mysqltuner.pl/ | perl
Check the results on your server
>> MySQLTuner 1.7.5 - Major Hayden <[email protected]> >> 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 [OK] Currently running supported MySQL version 5.5.58-cll [OK] Operating on 64-bit architecture -------- Log file Recommendations ------------------------------------------------------------------ -------- Storage Engine Statistics ----------------------------------------------------------------- [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA [--] Data in MyISAM tables: 143K (Tables: 5) [--] Data in InnoDB tables: 448K (Tables: 14) [OK] Total fragmented tables: 0 -------- 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: 17d 19h 5m 0s (11K q [0.008 qps], 5K conn, TX: 1005K, RX: 903K) [--] Reads / Writes: 100% / 0% [--] Binary logging is disabled [--] Physical Memory : 1.0G [--] Max MySQL memory : 583.2M [--] Other process memory: 413.3M [--] Total buffers: 168.0M global + 2.8M per thread (151 max threads) [--] P_S Max memory usage: 0B [--] Galera GCache Max memory usage: 0B [OK] Maximum reached memory usage: 170.8M (16.67% of installed RAM) [OK] Maximum possible memory usage: 583.2M (56.96% of installed RAM) [OK] Overall possible memory usage with other process is compatible with memory available [OK] Slow queries: 0% (0/11K) [OK] Highest usage of available connections: 0% (1/151) [OK] Aborted connections: 0.08% (4/5073) [!!] 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 / 5K selects) [OK] Query cache prunes per day: 0 [OK] No Sort requiring temporary tables [OK] No joins without indexes [OK] Temporary tables created on disk: 0% (0 on disk / 26 total) [!!] Thread cache is disabled [OK] Table cache hit rate: 78% (26 open / 33 opened) [OK] Open file limit used: 0% (18/10K) [OK] Table locks acquired immediately: 100% (1K immediate / 1K locks) -------- Performance schema ------------------------------------------------------------------------ [--] Performance schema is disabled. [--] Memory used by P_S: 0B [--] Sys schema isn't installed. -------- ThreadPool Metrics ------------------------------------------------------------------------ [--] ThreadPool stat is disabled. -------- MyISAM Metrics ---------------------------------------------------------------------------- [!!] Key buffer used: 18.2% (1M used / 8M cache) [OK] Key buffer size / total MyISAM indexes: 8.0M/158.0K [OK] Read Key buffer hit rate: 100.0% (3K cached / 1 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/448.0K [!!] Ratio InnoDB log file size / InnoDB Buffer pool size (7.8125 %): 5.0M * 2/128.0M should be equal 25% [OK] InnoDB buffer pool instances: 1 [--] InnoDB Buffer Pool Chunk Size not used or defined in your version [OK] InnoDB Read buffer efficiency: 98.66% (29303 hits/ 29702 total) [!!] InnoDB Write Log efficiency: 0% (1 hits/ 0 total) [OK] InnoDB log waits: 0.00% (0 waits / 1 writes) -------- Recommendations --------------------------------------------------------------------------- General recommendations: Control warning line(s) into /var/lib/mysql/zen.gozenhost.com.err file Enable the slow query log to troubleshoot bad queries Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1 Set thread_cache_size to 4 as a starting value Consider installing Sys schema from https://github.com/mysql/mysql-sys Read this before changing innodb_log_file_size and/or innodb_log_files_in_group: http://bit.ly/2wgkDvS Variables to adjust: query_cache_size (=0) query_cache_type (=0) query_cache_limit (> 1M, or use smaller result sets) thread_cache_size (start at 4) innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
MySQLTuner offers suggestions regarding how to better the database’s performance.
If you are wary about updating your database on your own, following MySQLTuner’s suggestions is one of the safer ways to improve your database performance.
Leave a Reply