MySQL Optimization - MySQL's maximum memory usage is dangerously high

Operating System & Version
CloudLinux v7.9.0 kvm (Centos 7.9)
cPanel & WHM Version
v100.0.1

johncarlopogix

Registered
Oct 31, 2021
4
3
3
public_html
cPanel Access Level
Website Owner
I have a cPanel/CentOS 7.9 (cloudlinux) VPS with 4 GB RAM.


I ran the MySQLTuner script, and followed the recommendations that they gave, but it's still recommending increases, while telling me that MySQL's maximum memory usage is dangerously high.



My current config in my my.cnf file is:


Code:
[mysql]
port                            = 3306
socket                          = /var/lib/mysql/mysql.sock

[mysqld]
performance_schema = on
basedir                         = /usr
bind_address                    = 127.0.0.1
datadir                         = /var/lib/mysql
max_allowed_packet              = 256M
max_connect_errors              = 1000000
pid_file                        = /var/lib/mysql/mysql.pid
port                            = 3306
skip_external_locking
socket                          = /var/lib/mysql/mysql.sock
tmpdir                          = /tmp
user                            = mysql

default_storage_engine          = InnoDB
innodb_buffer_pool_instances    = 4
innodb_buffer_pool_size         = 4G
innodb_file_per_table           = 1
innodb_flush_log_at_trx_commit  = 0
innodb_flush_method             = O_DIRECT
innodb_log_buffer_size          = 16M
innodb_log_file_size            = 1G
innodb_stats_on_metadata        = 0
innodb_read_io_threads          = 64
innodb_write_io_threads         = 64

query_cache_limit              = 2M
query_cache_size               = 0
query_cache_type               = 0

key_buffer_size                 = 32M

low_priority_updates            = 1
concurrent_insert               = 2

max_connections                 = 100

back_log                        = 512
thread_cache_size               = 100
thread_stack                    = 192K

interactive_timeout             = 180
wait_timeout                    = 180

innodb_sort_buffer_size         = 512M
join_buffer_size                = 4M
read_buffer_size                = 3M
read_rnd_buffer_size            = 4M
sort_buffer_size                = 4M

max_heap_table_size             = 128M
tmp_table_size                  = 128M

ft_min_word_len                 = 3

log_error                       = /var/lib/mysql/mysql_error.log
log_queries_not_using_indexes   = 1
long_query_time                 = 5
slow_query_log                  = 0
slow_query_log_file             = /var/lib/mysql/mysql_slow.log

[mysqldump]
quick
quote_names
max_allowed_packet              = 512M

I restarted MySQL a short while ago to apply my most recent changes.

When I run the script, this is what I get:

Code:
 >>  MySQLTuner 1.8.5 - 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.3.31-MariaDB-cll-lve
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/lib/mysql/mysql_error.log exists
[--] Log file: /var/lib/mysql/mysql_error.log(151K)
[OK] Log file /var/lib/mysql/mysql_error.log is not empty
[OK] Log file /var/lib/mysql/mysql_error.log is smaller than 32 Mb
[OK] Log file /var/lib/mysql/mysql_error.log is readable.
[!!] /var/lib/mysql/mysql_error.log contains 911 warning(s).
[!!] /var/lib/mysql/mysql_error.log contains 5 error(s).
[--] 23 start(s) detected in /var/lib/mysql/mysql_error.log
[--] 1) 2021-11-01  2:16:53 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 2) 2021-11-01  1:55:23 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 3) 2021-11-01  1:26:25 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 4) 2021-10-30 22:14:42 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 5) 2021-10-30 21:42:56 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 6) 2021-10-30 13:18:21 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 7) 2021-10-30 13:09:44 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 8) 2021-10-30 10:37:44 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 9) 2021-10-29  0:44:51 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 10) 2021-10-29  0:25:05 0 [Note] /usr/sbin/mysqld: ready for connections.
[--] 22 shutdown(s) detected in /var/lib/mysql/mysql_error.log
[--] 1) 2021-11-01  2:16:49 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 2) 2021-11-01  1:55:19 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 3) 2021-11-01  1:25:51 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 4) 2021-10-30 22:14:07 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 5) 2021-10-30 21:42:52 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 6) 2021-10-30 13:18:17 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 7) 2021-10-30 13:09:40 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 8) 2021-10-30 10:37:08 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 9) 2021-10-29  0:44:47 0 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 10) 2021-10-29  0:25:01 0 [Note] /usr/sbin/mysqld: Shutdown complete

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in MyISAM tables: 28.7K (Tables: 10)
[--] Data in InnoDB tables: 16.2M (Tables: 90)
[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: 53s (52 q [0.981 qps], 25 conn, TX: 66K, RX: 4K)
[--] Reads / Writes: 100% / 0%
[--] Binary logging is disabled
[--] Physical Memory     : 3.6G
[--] Max MySQL memory    : 30.9G
[--] Other process memory: 0B
[--] Total buffers: 4.3G global + 271.2M per thread (100 max threads)
[--] P_S Max memory usage: 95M
[--] Galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 4.9G (136.42% of installed RAM)
[!!] Maximum possible memory usage: 30.9G (856.04% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/52)
[OK] Highest usage of available connections: 2% (2/100)
[!!] Aborted connections: 4.00%  (1/25)
[!!] 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] No Sort requiring temporary tables
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (0 on disk / 4 total)
[OK] Thread cache hit rate: 92% (2 created / 25 connections)
[!!] Table cache hit rate: 5% (1 hits / 19 requests)
[OK] table_definition_cache(400) is upper than number of tables(367)
[OK] Open file limit used: 0% (23/32K)
[OK] Table locks acquired immediately: 100% (11 immediate / 11 locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 95.7M
[--] Sys schema is installed.

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

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (6M used / 33M cache)
[OK] Key buffer size / total MyISAM indexes: 32.0M/91.0K
[!!] Read Key buffer hit rate: 50.0% (8 cached / 4 reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 4.0G/16.2M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (50 %): 1.0G * 2/4.0G should be equal to 25%
[OK] InnoDB buffer pool instances: 4
[--] Number of InnoDB Buffer Pool Chunk : 32 for 4 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[!!] InnoDB Read buffer efficiency: 39.35% (929 hits/ 2361 total)
[!!] InnoDB Write Log efficiency: 0% (1 hits/ 0 total)
[OK] InnoDB log waits: 0.00% (0 waits / 1 writes)

-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/0B

-------- 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/lib/mysql/mysql_error.log file
    Check error line(s) in /var/lib/mysql/mysql_error.log file
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Reduce or eliminate unclosed connections and network issues
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64: https://bit.ly/2Fulv7r
    Read this before increasing for MariaDB https://mariadb.com/kb/en/library/optimizing-table_open_cache/
    This is MyISAM only table_cache scalability problem, InnoDB not affected.
    See more details here: https://bugs.mysql.com/bug.php?id=49177
    This bug already fixed in MySQL 5.7.9 and newer MySQL versions.
    Beware that open_files_limit (32135) variable
    should be greater than table_open_cache (2000)
    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 ***
    table_open_cache (> 2000)
    innodb_log_file_size should be (=512M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

Does anyone have any recommendations with what to do now?




Thanks a lot!
 

cPanelAnthony

Administrator
Staff member
Oct 18, 2021
1,032
101
118
Houston, TX
cPanel Access Level
Root Administrator
Hello! It's hard to say for sure how you should optimize MySQL. 4GB of RAM is not a whole lot; it could depend on how many databases you have, how active each database is, what kind of queries or work is being done with each database, how large the databases are, etc... It could simply be that your server doesn't have enough RAM for the amount of work the databases are performing.

With that being said, I am not a systems administrator and cannot make any promises in regards to what you need to do in order to get MySQL running smoothly. Perhaps some of the other users here will be able to offer some guidance.
 

RoseHosting

Active Member
PartnerNOC
Jan 3, 2003
34
10
158
You can lower your innodb_buffer_pool_size value, because according to your MySQL Tuner script result, your InnoDB data size is only around 16MB.