Reducing MySQL RAM Usage

July 8, 2020 at 12:16 PM PDT

I host this site on a $5 DigitalOcean droplet, and it works pretty well. The only drawback is that it has a fairly limited RAM allocation, and with the need to run a MySQL server to run a WordPress Ghost instance, it causes things to run slower at times.

After a little bit of research, I found a simple solution to fix some of the high usage. MySQL has what is called the performance schema, which allocates memory at the start of mysqld, instead of as it is needed, which can obviously help with caching and performance under load. But since my site isn't very popular yet, and my server is on a budget, I have no need for these optimizations, so I can safely disable it. Here's how to do it in Ubuntu.

First, open a root/sudo terminal for your server. Then, add the line performance_schema = off to your my.cnf file under [mysqld] (you may need to add that in too). Last, restart the mysql service.

sudo vim /etc/mysql/my.cnf

## `Insert performance_schema = off` under `[mysqld]`

sudo systemctl restart mysql

That's all there is to it. If you want to know more, here's my source: Starting MySQL On Low Memory Virtual Machines by MariaDB.