Tuning MariaDB on a VPS: the few settings worth changing, and how to measure

Databases·· 19 views· 3 min read

The short answer: MariaDB already comes with reasonable values. Tuning only pays when you have measured that the database is the bottleneck. Then nearly all the gain comes from one setting (the memory the database uses to keep data), and the rest is not breaking things. Change one thing at a time and measure.

The settings that matter

Setting What it does
innodb_buffer_pool_size The memory where InnoDB keeps the data and indexes it has read. This is the one that weighs most. Bigger helps, but it must fit in RAM alongside PHP and the web server, or the server runs out of memory.
max_connections How many connections at once. Raise it only if you see “Too many connections”; each connection costs memory.
slow_query_log and long_query_time They record slow queries. They speed nothing up; they show where the problem is: Slow queries.
Per-connection buffers Leave them at the default. Large values multiply by every connection and blow the memory.
The query cache Do not switch it on for a site that writes a lot: it usually makes things worse.

Step by step

1 Measure first: switch on the slow query log and watch the load with Seeing what uses CPU, memory and disk. A badly written query or a missing index is not fixed by more memory.
2 Back up the configuration and the database: Backing up with mysqldump.
3 Create a file of your own in the configuration folder (on Ubuntu or Debian, in /etc/mysql/mariadb.conf.d/, for example 99-local.cnf) instead of editing the system’s. Put in it only the setting you change.
4 Pick a prudent value for the buffer pool, without leaving the server short of memory for the rest. If in doubt, start low and go up.
5 Restart (sudo systemctl restart mariadb) and confirm the value with SHOW VARIABLES LIKE 'innodb_buffer_pool_size';. Measure again, under the same conditions.
If MariaDB does not start after the change, it was almost always a value that does not fit or a typo in the file. Take your file out, start it, and read the error: Reading systemctl status. And do not change five things at once: you will not know which one helped.
“MySQL server has gone away” often points to something else (a big packet, a timeout), not a lack of tuning: The causes, in order. If the server runs out of memory, see Out of memory on a VPS.

Want an opinion on your server’s numbers? Open a ticket with the VPS plan and what you measured.

Open a support ticket

SEE ALSO

Slow queries: how to find them and the fixes that work most often

MySQL or MariaDB: which one runs here, and does it matter

MySQL server has gone away: the causes, in order of likelihood

CPU, RAM and disk I/O in plain words: what each one limits on your site

Out of memory on a VPS: what the OOM killer is and what to do

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from $7.61/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.