{"id":1140,"date":"2026-09-16T03:39:57","date_gmt":"2026-09-16T03:39:57","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1140"},"modified":"2026-09-16T03:39:57","modified_gmt":"2026-09-16T03:39:57","slug":"how-to-reduce-mysql-memory-usage-small-server","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/","title":{"rendered":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A MySQL or MariaDB server that swaps, gets OOM-killed, or refuses new connections is almost always misconfigured for the memory it has \u2014 not short of memory. On a 1 GB or 2 GB VPS you cannot give the database &#8220;enough&#8221; RAM, so you have to give it the right RAM. This guide walks through exactly where MySQL&#8217;s memory goes, which settings to cut, and how to verify the result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Everything here targets MySQL 8.0 and MariaDB 10.6+ on Debian or Ubuntu. The numbers assume a small VPS also running Nginx and PHP-FPM, so the database gets roughly half the machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Calculate What MySQL Is Actually Using<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Do not guess. Two queries give you the real picture \u2014 global buffers (allocated once at startup) and per-connection buffers (multiplied by every open connection and potentially by every thread that runs a query):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -e \"\nSELECT\n  @@innodb_buffer_pool_size\/1024\/1024 AS buffer_pool_mb,\n  @@key_buffer_size\/1024\/1024 AS key_buffer_mb,\n  @@tmp_table_size\/1024\/1024 AS tmp_table_mb,\n  @@max_heap_table_size\/1024\/1024 AS max_heap_mb,\n  @@max_connections,\n  @@sort_buffer_size\/1024\/1024 AS sort_mb,\n  @@read_buffer_size\/1024\/1024 AS read_mb,\n  @@join_buffer_size\/1024\/1024 AS join_mb;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Estimated worst-case memory is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total = buffer_pool + key_buffer + tmp_table\n      + (max_connections * (sort + read + join + binlog_cache + net + thread_stack))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a default install, <code>max_connections<\/code> of 151 multiplied by even 1 MB of per-connection buffers is 151 MB of potential overhead \u2014 before the buffer pool. That is often what pushes a small VPS into swap.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the InnoDB Buffer Pool to Fit Your Machine<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For a VPS where the database shares RAM with the web tier, 256 MB is the right starting point on a 1 GB machine and 512\u2013768 MB on a 2 GB machine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/mysql\/mysql.conf.d\/90-small.cnf   (MySQL)\n# \/etc\/mysql\/mariadb.conf.d\/90-small.cnf (MariaDB)\n[mysqld]\ninnodb_buffer_pool_size = 256M\ninnodb_buffer_pool_instances = 1\ninnodb_log_buffer_size = 16M\ninnodb_flush_method = O_DIRECT<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>innodb_buffer_pool_instances = 1<\/code> is deliberate: splitting a small pool creates contention without benefit. <code>O_DIRECT<\/code> avoids double-caching the same pages in the OS page cache and the buffer pool, which on a small machine effectively doubles your usable database cache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a 1 GB VPS, also shrink the redo log so it does not dominate disk and memory during checkpoints:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>innodb_log_file_size = 64M<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Cut the Per-Connection Buffers Aggressively<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is where the biggest wins are on small servers, and where most guides go wrong by leaving defaults. Every connection can allocate these buffers, so keep them tiny and let the buffer pool absorb the load:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_connections = 50\nthread_cache_size = 16\nsort_buffer_size = 256K\nread_buffer_size = 128K\nread_rnd_buffer_size = 128K\njoin_buffer_size = 128K\nbinlog_cache_size = 32K\nthread_stack = 192K\nnet_buffer_length = 8K<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then eliminate the connection churn that makes <code>max_connections<\/code> matter at all:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wait_timeout = 120\ninteractive_timeout = 120<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If your application opens a connection per request, install a pooler rather than raising limits \u2014 a single PHP-FPM pool holding 10 persistent connections will serve far more traffic than 100 connections opened and closed continuously.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Stop Temporary Tables From Eating Disk and RAM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Small servers usually have both slow disk and little RAM, so disk-based temporary tables are doubly painful. Keep temp tables in memory, but cap them hard:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tmp_table_size = 32M\nmax_heap_table_size = 32M\ninternal_tmp_mem_storage_engine = MEMORY\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the two size values equal \u2014 MySQL uses the smaller of the two, and mismatched values are a common source of confusion. Then watch whether you are still spilling:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -e \"SHOW GLOBAL STATUS LIKE 'Created_tmp%';\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A high <code>Created_tmp_disk_tables<\/code> relative to <code>Created_tmp_tables<\/code> means queries are sorting or grouping too much data. The fix is an index, not a bigger limit \u2014 raising <code>tmp_table_size<\/code> further just delays the same spill while consuming RAM you do not have.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Disable What You Are Not Using<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every feature you are not using costs memory. On a small web server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>performance_schema = OFF\n# MariaDB only:\n# aria_pagecache_buffer_size = 16M\n# if you use only InnoDB:\n# skip-innodb does not exist in 8.0; instead reduce stats:\ninnodb_stats_persistent_sample_pages = 20<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>performance_schema = OFF<\/code> alone reclaims 100\u2013200 MB on MySQL 8.0, which is a huge fraction of a 1 GB VPS. Re-enable it temporarily if you need to diagnose a lock issue, then turn it back off. If you use MariaDB, shrink the Aria page cache unless you rely on Aria tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Verify the Server Is Actually Healthy Under Load<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Restart and confirm the settings took effect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mysql\nmysql -e \"SHOW VARIABLES LIKE 'innodb_buffer_pool_size';\"\nfree -m\nmysqladmin status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then generate load and watch for the failure you were trying to prevent \u2014 swapping and OOM kills:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><pre><code># In one terminal\nsysbench \/usr\/share\/sysbench\/oltp_read_write.lua --mysql-user=root \\\n  --mysql-db=bench --table-size=100000 --threads=4 --time=120 run<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># In another\nwatch -n2 'free -m; echo ---; grep -i \"out of memory\\|oom\" \/var\/log\/syslog | tail -5'<\/code><\/pre><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like: available memory never drops near zero, swap usage stays flat, and no OOM messages appear. If MySQL still swaps, cut the buffer pool by another 25% \u2014 a smaller cache that fits in RAM always beats a larger one that forces pages out to disk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Know When to Stop Tuning and Buy More RAM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There is a floor below which tuning cannot go. If your working set genuinely exceeds what the buffer pool can hold, you will see persistent disk reads and unresponsive queries no matter how tight the config is. Check the cache hit ratio:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -e \"\nSELECT\n  ROUND(100 * (1 - (SELECT VARIABLE_VALUE FROM performance_schema.global_status\n    WHERE VARIABLE_NAME='Innodb_buffer_pool_reads') \/\n  (SELECT VARIABLE_VALUE FROM performance_schema.global_status\n    WHERE VARIABLE_NAME='Innodb_buffer_pool_read_requests')), 2) AS hit_pct;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Above 99% is healthy. Below 97% with a working set that cannot shrink, it is time for a larger plan \u2014 or a plan whose storage delivers consistent IOPS so the reads you cannot cache are at least fast. If that is where you have landed, <a href=\"https:\/\/virtualserversvps.com\/#providers\">our VPS comparison table<\/a> lists plans with their measured IOPS and memory ceilings so you can size the upgrade against real numbers instead of spec sheets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pair this with correct swap sizing \u2014 a small, well-placed swapfile is a safety net, not a substitute for RAM. See our guide to <a href=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/\">swap space on a VPS<\/a> for the numbers that work on small servers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A MySQL or MariaDB server that swaps, gets OOM-killed, or refuses new connections is almost always misconfigured for the memory it has \u2014 not short of memory. On a 1&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1140","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Reduce MySQL Memory Usage on a Small Server (1-2 GB) - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)\" \/>\n<meta property=\"og:description\" content=\"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-16T03:39:57+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/\",\"name\":\"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB) - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-16T03:39:57+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB) - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/","og_locale":"en_US","og_type":"article","og_title":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)","og_description":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)","og_url":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-16T03:39:57+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/","url":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/","name":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB) - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-16T03:39:57+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-reduce-mysql-memory-usage-small-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Reduce MySQL Memory Usage on a Small Server (1-2 GB)"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1140"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1140\/revisions"}],"predecessor-version":[{"id":1147,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1140\/revisions\/1147"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}