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.
- Navigate to /etc/yum.repos.d/ on your CentOS box.
- Create a new file called MariaDB.repo.
- 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
- 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
- Install the required packages onto your server.
yum install MariaDB-server MariaDB-client
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.
- Backup the original configuration file by renaming it.
mv /etc/my.cnf /etc/my.bak
- 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
- Start the MariaDB service (daemon).
service mysql start
- 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.
- Run the secure installation script. MariaDB must be running before this script can be executed.
- You are prompted to enter the password for root. Since none exists, you can press Enter to continue.
- A prompt to change the password for root will appear. Press ‘Y’ and then Enter to set one.
- Next you will be prompted to remove anonymous users. Press ‘Y’ and then Enter to do so,
- When asked to disallow root remote login, press ‘Y’ and then Enter. Your root account should never have remote access.
- When prompted to remove the test database, press ‘Y’ and then Enter.
- 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 -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