Location of MySQL – MariaDB configuration file on Debian 11 and Tuning It

Locate mariadb config files:

# cd /etc/mysql/mariadb.conf.d
# ls -la
total 28
drwxr-xr-x 2 root root 4096 Sep 23 22:52 .
drwxr-xr-x 4 root root 4096 Sep 30 18:20 ..
-rw-r--r-- 1 root root  575 Feb 17  2022 50-client.cnf
-rw-r--r-- 1 root root  231 Feb 17  2022 50-mysql-clients.cnf
-rw-r--r-- 1 root root  927 Feb 17  2022 50-mysqld_safe.cnf
-rw-r--r-- 1 root root 3666 Feb 19  2022 50-server.cnf
-rw-r--r-- 1 root root  570 Feb 17  2022 60-galera.cnf

Tweaking mariadb
To optimize the server, edit 50-server.cnf

root@webserver:/etc/mysql/mariadb.conf.d# nano 50-server.cnf

my.cnf Files
MariaDB is normally configured by editing the my.cnf file.

The following my.cnf example files were included with MariaDB until MariaDB 10.3.0. If present, you can examine them to see more complete examples of some of the many ways to configure MariaDB and use the one that fits you best as a base. Note that these files are now quite outdated, so what was huge a few years ago may no longer be seen as such.

my-small.cnf
my-medium.cnf
my-large.cnf
my-huge.cnf

Run the tuner

wget http://mysqltuner.pl/ -O mysqltuner.pl
Then execute it:
perl mysqltuner.pl

Create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Leave a Comment