Updated: 11 October 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9 (MariaDB 10.11 / MySQL 8)
Good MariaDB/MySQL performance comes mostly from a few settings, efficient queries and enough RAM. These tips apply to MariaDB 10.11 and MySQL 8.0/8.4 on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.
Start by measuring
- Enable the slow query log (see "How to separate MySQL Slow Log Using "Logrotate" in Ubuntu?") and fix the slowest queries first, usually with the right indexes. Use
EXPLAIN SELECT …to see how a query is executed. - Run MySQLTuner after the server has been up for at least a day:
apt install mysqltuner(or downloadmysqltuner.plfrom its GitHub project), thenmysqltuner. Treat its advice as suggestions.
Key settings
In /etc/mysql/mariadb.conf.d/60-tuning.cnf (Ubuntu/Debian) or /etc/my.cnf.d/tuning.cnf (AlmaLinux/Rocky):
[mariadb] innodb_buffer_pool_size = 2G innodb_log_file_size = 512M max_connections = 150 tmp_table_size = 64M max_heap_table_size = 64M slow_query_log = 1 long_query_time = 2
innodb_buffer_pool_size: the most important one. On a server that only runs the database, 50 to 70% of RAM; on a server that also runs the web server and PHP, much less (for example 25%).max_connections: each connection uses memory. Raise it only if you see "Too many connections"; persistent connections from PHP are a common cause.tmp_table_sizeandmax_heap_table_size: set both to the same value.- The query cache is removed in MySQL 8 and off by default in MariaDB; leave it off.
Restart after changes (systemctl restart mariadb) and check the values with mariadb -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size'".
Maintenance
- Use InnoDB for all tables; convert old MyISAM tables with
ALTER TABLE t ENGINE=InnoDB;. - Keep MariaDB/MySQL updated with the system updates.
- Watch disk space: a full disk stops the database.
Note: On a cPanel server, edit /etc/my.cnf and restart with /scripts/restartsrv_mysql. On shared hosting, database settings are managed by Ucartz; query optimisation in your application is what you can change.