Installing and Configuring MariaDB 10 on CentOS 6

Overview

This tutorial will guide you through the deployment process of MariaDB on a Red Hat-based Linux server, such as CentOS. We’ll start by configuring the hardware and then move into the installation and configuration of MariaDB.

MariaDB is a fork of the very popular and open source MySQL database, which is now owned by Oracle. In fact, the two were created by the same individual. They are essentially a mirror of each other, so a lot of the knowledge used to run MySQL can be used for MariaDB. This should make migration easier to swallow.

Install MariaDB

Add the MariaDB Repository

We can add the repository to our server to make installing the database service a lot easier – plus we’ll ensure patches are more easily accessible.

  1. Navigate to /etc/yum.repos.d/ on your CentOS box.
  2. Create a new file called MariaDB.repo.
  3. For 64-bit installs of CentOS, add the following lines.
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.0/centos6-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
  4. For 32-bit installs of CentOS, add the following lines.
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.0/centos6-x86
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
  5. Install the required packages onto your server.
    yum install MariaDB-server MariaDB-client

Configuring MariaDB

The configuration files and binaries for MariaDB are mostly the same as MySQL. For example, both use a configuration file called my.cnf. Even the daemon binary is called mysql. This is done done to ensure people can more easily migrate from MySQL.

The default configuration file is too liberal. It should not be used in either testing or production. If you are just playing around and learning the software, however, it should be fine.

The MariaDB installation includes several  configuration file templates that can be used to quickly configure the server. The one you choose depends on how large you expect your databases to get.

my-small.cnf Ideal for servers with a very limited amount RAM (64MB or less) available for your databases. An example would be a small LAMP server hosting all web-related roles.
my-medium.cnf Ideal for dedicated database servers with 128MB of available memory or less. Another good example for multi-role servers.
my-large.cnf Ideal for for servers with at least 512MB of RAM available for the database server.
my-huge.cnf Ideal for servers with 1GB of RAM or more available to the database server.

 

  1. Backup the original configuration file by renaming it.
    mv /etc/my.cnf /etc/my.bak
  2. Create a new my.cnf file by copying an existing template. We’ll use the medium server template for this example.
    cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
  3. Start the MariaDB service (daemon).
    service mysql start
    That is not a typo. MariaDB’s service name is mysql.
  4. Configure MariaDB to start automatically when the system is booted.
    chkconfig mysql on

Securing the Installation

The default installation includes settings and accounts that are good for testing, but they will make your server a fairly large security target.

One example is the Root database account – it has no set password. Anyone can access your databases just knowing this account name. Thankfully, much like MySQL, we can run a script that walks us through closing these security concerns.

  1. Run the secure installation script. MariaDB must be running before this script can be executed.
    /usr/bin/mysql_secure_installation
  2. You are prompted to enter the password for root. Since none exists, you can press Enter to continue.
  3. A prompt to change the password for root will appear. Press ‘Y’ and then Enter to set one.
  4. Next you will be prompted to remove anonymous users. Press ‘Y’ and then Enter to do so,
  5. When asked to disallow root remote login, press ‘Y’ and then Enter. Your root account should never have remote access.
  6. When prompted to remove the test database, press ‘Y’ and then Enter.
  7. Finally, you will be asked to reload the privileges table. Press ‘Y’ and then Enter. This will flush out the old permissions to apply the new ones.

Logging into MariaDB

The administer the server and create databases we need to log in. To do this we use the following command.
mysql -u <username> -p
The -u switch tells MariaDB which user account to log in with, and the -p switch tells it to prompt us for a password. To log in as root, we would do the following.

mysql -u root -p