Databases

Where is my.cnf? MySQL and MariaDB config files explained

Find the MySQL or MariaDB config files on Ubuntu, Debian, AlmaLinux and Rocky Linux, learn the order they load in, and confirm which settings are really active.

BeginnerLinux server5 min read

Guides often say "add this line to my.cnf", but on a modern Linux server my.cnf is usually just a list of other files to read. Edit the wrong one and your change either does nothing or gets overwritten by a package update. This guide shows where MySQL and MariaDB look for settings, which file you should edit, and how to confirm a change took effect.

Before you start

  • MySQL or MariaDB installed on your Linux VPS.
  • A user with sudo rights.
  • Know which server you run. mysql --version shows MariaDB in the output for MariaDB, and just a version number for MySQL.

How MySQL and MariaDB read config files

The server reads a fixed list of option files at startup. Settings in files read later override the same setting from earlier files. Ask the server binary for its own list:

Bash
mysqld --verbose --help 2>/dev/null | grep -A1 "Default options"

On recent MariaDB releases the binary is mariadbd, so run the same command with mariadbd if mysqld is not found. Typical output:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Inside those files, two directives pull in more files:

  • !include /path/file.cnf reads one extra file.
  • !includedir /path/dir/ reads every .cnf file in that folder.

Within each file, settings sit under group headers. The server reads [mysqld] (and [mariadb] on MariaDB). Client tools such as mysql and mysqldump read [client]. A line under the wrong header is ignored by the server.

Ubuntu and Debian

Both MySQL and MariaDB packages use /etc/mysql/. /etc/mysql/my.cnf is a short file, sometimes a symlink, that includes folders.

MySQL

  • /etc/mysql/my.cnf includes /etc/mysql/conf.d/ and /etc/mysql/mysql.conf.d/.
  • The main server settings are in /etc/mysql/mysql.conf.d/mysqld.cnf.

MariaDB

  • /etc/mysql/my.cnf points to /etc/mysql/mariadb.cnf, which includes /etc/mysql/conf.d/ and /etc/mysql/mariadb.conf.d/.
  • The main server settings are in /etc/mysql/mariadb.conf.d/50-server.cnf.

AlmaLinux and Rocky Linux

The RHEL family uses /etc/my.cnf, which includes /etc/my.cnf.d/.

  • MariaDB from AppStream: server settings in /etc/my.cnf.d/mariadb-server.cnf.
  • MariaDB from the MariaDB repository: server settings in /etc/my.cnf.d/server.cnf.
  • MySQL from AppStream: server settings in /etc/my.cnf.d/mysql-server.cnf.

If you are unsure, list the folder and search for the [mysqld] header:

Bash
grep -rl "^\[mysqld\]" /etc/my.cnf /etc/my.cnf.d/ /etc/mysql/ 2>/dev/null

Which file should you edit?

Put your own changes in a new file in the server's include folder rather than editing the packaged file. Package updates then cannot overwrite them, and you can see all your changes in one place. Name it so it sorts last:

  • Ubuntu or Debian, MySQL: /etc/mysql/mysql.conf.d/99-custom.cnf
  • Ubuntu or Debian, MariaDB: /etc/mysql/mariadb.conf.d/99-custom.cnf
  • AlmaLinux or Rocky Linux: /etc/my.cnf.d/99-custom.cnf

Example content, with values you should adjust for your server's RAM:

INI
[mysqld]
bind-address = 127.0.0.1
max_connections = 100
innodb_buffer_pool_size = 512M

Tip: Set each option in one file only. MariaDB reads included folders in alphabetical order, but do not rely on ordering to resolve conflicts between files.

Apply and check the change

Warning: A typo in a config file can stop the database from starting, which takes your sites offline. Keep a copy of any file before you edit it, and restart during a quiet period.

On MySQL 8.0 and later, test the config before restarting:

Bash
sudo mysqld --validate-config

No output means the config is valid. MariaDB has no equivalent flag, so restart and check the status straight away. Restart the service; its name differs by system:

Bash
sudo systemctl restart mysql      # MySQL on Ubuntu and Debian
sudo systemctl restart mysqld     # MySQL on AlmaLinux and Rocky Linux
sudo systemctl restart mariadb    # MariaDB everywhere

Check it works

The config files show what you asked for. The running server shows what it is actually using. Check the live value:

SQL
SHOW GLOBAL VARIABLES LIKE 'max_connections';
SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size';

The buffer pool size is shown in bytes, so 536870912 equals 512M.

To see every option the server would read from all files, merged, run:

Bash
my_print_defaults mysqld

On MySQL, also check for settings saved with SET PERSIST. They are stored in mysqld-auto.cnf in the data folder, usually /var/lib/mysql/, and override the .cnf files:

SQL
SELECT * FROM performance_schema.persisted_variables;

Troubleshooting

  • Change has no effect: the line is under the wrong group header, a later file sets the same option, or a SET PERSIST value overrides it. Check with my_print_defaults and persisted_variables.
  • Server fails to start after an edit: read sudo journalctl -u mysql -n 50 (or mysqld or mariadb). The log usually names the unknown option or bad value. Fix it or restore your copy.
  • unknown variable error: the option does not exist in your version, or it is MySQL-only or MariaDB-only. Check the reference for your exact version.
  • mysqld: command not found: the binary is in /usr/sbin, which may not be in your path. Use /usr/sbin/mysqld or /usr/sbin/mariadbd.
  • Client keeps asking for a password: a [client] section in ~/.my.cnf can hold credentials for that Linux user only. Keep that file at chmod 600.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.