loading...

Ubuntu Server 18.04 – Understanding the MariaDB configuration files

How to install Chocolatey on Windows 10

Now that we have MariaDB installed, let’s take a quick look at how its configuration is stored. While we won’t be changing much of the configuration in this chapter (aside from adding parameters related to setting up a slave), it’s a good idea to know where to find the configuration, since you’ll likely be asked by a developer to tune the database configuration at some point in your career. This may involve changing the storage engine, buffer sizes, or countless other settings. A full walkthrough on performance tuning is outside the scope of this tutorial, but it will be helpful to know how the settings for MariaDB are read, since Ubuntu’s implementation is fairly unique.

The configuration files for MariaDB are stored in the /etc/mysql directory. In that directory, you’ll see the following files by default:

debian.cnf 
debian-start 
mariadb.cnf 
my.cnf 
my.cnf.fallback 

You’ll also see the following directories:

conf.d 
mariadb.conf.d 

The configuration file that MariadDB reads on startup is the /etc/mysql/mariadb.cnf file. This is where you’ll begin perusing when you want to configure the daemon, but we’ll get to that soon. The /etc/mysql/debian-start file is actually a script that sets default values for MariaDB when it starts, such as setting some environment variables. It also defines a SIGHUP trap that is executed if the mariadb process receives the SIGHUP signal, which will allow it to check for crashed tables.

The debian-start script also loads the /etc/mysql/debian.cnf file, which sets some client settings for the mariadb daemon. Here’s a list of values from that file:

[client] 
host     = localhost 
user     = root 
password =  
socket   = /var/run/mysqld/mysqld.sock 
[mysql_upgrade] 
host     = localhost 
user     = root 
password =  
socket   = /var/run/mysqld/mysqld.sock 
basedir  = /usr 

The defaults for these values are fine and there’s rarely a reason to change them. Essentially, the file sets the default user, host, and socket location. If you’ve used MySQL before on other platforms, you may have seen many of those settings in the /etc/my.cnf file, which is typically the standard file for the mariadb daemon. With MariaDB on Ubuntu Server, you can see that the default layout of files was changed considerably.

The /etc/mysql/mariadb.cnf file sets the global defaults for MariaDB. However, in Ubuntu’s implementation, this default file just includes configuration files from the /etc/mysql/conf.d and the /etc/mysql/mariadb.conf.d directories. Within those directories, there are additional files ending with the .cnf extension. Many of these files contain default configuration values that would normally be found in a single file, but Ubuntu’s implementation modularizes these settings into separate files instead. For our purposes in this tutorial, we’ll be editing the /etc/mysql/conf.d/mysql.cnf file when it comes time to set up master and slave replication.

The other configuration files aren’t relevant for the content of this tutorial, and their current values are more than sufficient for what we need. When it comes to performance tuning, you may consider creating a new configuration file ending with the .cnf extension, with specific tuning values as provided by the documentation of a software package you want to run that interfaces with a database, or requirements given to you by a developer.

For additional information on how these configuration files are read, you can refer to the /etc/mysql/mariadb.cnf file, which includes some helpful contents at the top of the file that details the order in which these configuration files are read, as well as their purpose. Here’s an excerpt of these comments from that file:

# The MariaDB/MySQL tools read configuration files in the following order: 
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, 
# 2. "/etc/mysql/conf.d/*.cnf" to set global options. 
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. 
# 4. "~/.my.cnf" to set user-specific options. 

As we can see, when MariaDB starts up, it first reads the /etc/mysql/mariadb.cnf file, followed by.cnf files stored within the /etc/mysql/conf.d directory, then the .cnf files stored within the /etc/mysql/mariadb.conf.d directory, followed by any user-specific settings stored within a .my.cnf file that may be present in the user’s home directory.

With Ubuntu’s implementation, when the /etc/mysql/mariadb.cnf file is read during startup, the process will immediately scan the contents of /etc/mysql/conf.d and /etc/mysql/mariadb.conf.d, because the /etc/mysql/mariadb.cnf file contains the following lines:

!includedir /etc/mysql/conf.d/ 
!includedir /etc/mysql/mariadb.conf.d/ 

As you can see, even though the order the configuration files are checked is set to check the mariadb.cnf file first, followed by the /etc/mysql/conf.d and /etc/mysql/mariadb.conf.d directories, the mariadb.cnf file simply tells the mariadb service to immediately check those directories.

This may be a bit confusing at first, because the default configuration for MariaDB in Ubuntu Server essentially consists of files that redirect to other files. But the main takeaway is that any configuration changes you make that are not exclusive to MariaDB (basically, configuration compatible with MySQL itself), should be placed in a configuration file the ends with the .cnf extension, and then stored in the /etc/mysql/conf.d directory. If the configuration you’re wanting to add is for a feature exclusive to MariaDB (but not compatible with MySQL itself), the configuration file should be placed in the /etc/mysql/mariadb.conf.d directory instead. For our purposes, we’ll be editing the /etc/mysql/conf.d/mysql.cnf file when it comes time to setting up our master/slave replication, since the method we’ll be using is not specific to MariaDB.

In this section, we discussed MariaDB configuration and how it differs from its implementation in other platforms. The way the configuration files are presented is not the only difference in Ubuntu’s implement of MariaDB; there are other differences as well. In the next section, we’ll take a look at a few additional ways in which Ubuntu’s implementation differs.

Comments are closed.

loading...