MariaDB LogoMariaDB is a binary drop in replacement for MySQL database server. This means that for most cases, you can just uninstall MySQL and install MariaDB and you are good to go.

Why MariaDB?

  • MariaDB is totally open source version of MySQL
  • It works just like MySQL and is compatible with MySQL setups
  • Fedora and Red Hat/CentOS is moving to use MariaDB from Fedora 19/RHEL 7/CentOS 7 versions

This is guide, howto install or upgrade MariaDB 10.2.7 [stable] (10.1.25 [stable] or 10.3.0 [alpha]) on Fedora 26/25/24, CentOS 7.4/6.9/5.11 and Red Hat (RHEL) 7.4/6.9/5.11. Installing MariaDB is almost same process than install MySQL.

Note: If you are moving from MySQL, then make sure that you backup (dump and copy) your database and configs. And if upgrading from earlier versions, then remember run mysql_upgrade command. And if you uninstall MySQL, then remember restore /etc/my.cnf after installation, like:


mv -vi /etc/my.cnf.rpmsave /etc/my.cnf

Install MariaDB/MariaDB-server 10.2.7/10.1.25/10.3.0 on Fedora 26/25/24/23, CentOS 7.4/6.9, Red Hat (RHEL) 7.4/6.9

1. Change root user


su -
## OR ##
sudo -i

2. Install MariaDB repository

You can grab your dnf/yum repo file using MariaDB repository configuration tool.

Fedora 26/25/24

Note: currently Fedora 26/25/24 users can install MariaDB 10.1 and not additional repos needed or alternatively use MariaDB repos to install newer/development versions or Galera Cluster.

3. Update or Install MariaDB 10.2/10.1/10.3

Fedora 26/25/24 (own packages)


dnf install mariadb mariadb-server

CentOS/Red Hat (RHEL) 7.4/6.9 (and Fedora 26/25/24 using MariaDB repos)


yum install MariaDB MariaDB-server

4. Start MariaDB server and autostart MariaDB on boot

Fedora 26/25/24 and CentOS/RHEL 7.4


systemctl start mariadb.service ## use restart after update

systemctl enable mariadb.service

CentOS 6.9 and Red Hat (RHEL) 6.9


service mysql start ## use restart after update
## OR ##
/etc/init.d/mysql start ## use restart after update

chkconfig --levels 235 mysql on

5. MariaDB (MySQL) Secure Installation

  • Set (Change) root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables

Start MariaDB (MySQL) Secure Installation with following command


/usr/bin/mysql_secure_installation

Output:


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we\'ll need the current
password for the root user.  If you\'ve just installed MariaDB, and
you haven\'t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from \'localhost\'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named \'test\' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you\'ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Note: If you don’t want some reason, do a “MySQL Secure Installation” then at least it’s very important to change the root user’s password


mysqladmin -u root password [your_password_here]

## Example ##
mysqladmin -u root password myownsecrectpass

6. Connect to MySQL database (localhost) with password


mysql -u root -p

## OR ##
mysql -h localhost -u root -p

7. Create Database, Create MySQL User and Enable Remote Connections to MySQL Database

This example uses following parameters:

  • DB_NAME = webdb
  • USER_NAME = webdb_user
  • REMOTE_IP = 10.0.15.25
  • PASSWORD = password123
  • PERMISSIONS = ALL

## CREATE DATABASE ##
MariaDB [(none)]> CREATE DATABASE webdb;

## CREATE USER ##
MariaDB [(none)]> CREATE USER 'webdb_user'@'10.0.15.25' IDENTIFIED BY 'password123';

## GRANT PERMISSIONS ##
MariaDB [(none)]> GRANT ALL ON webdb.* TO 'webdb_user'@'10.0.15.25';

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##
MariaDB [(none)]> FLUSH PRIVILEGES;

Enable Remote Connection to MariaDB Server –> Open MySQL Port (3306) on Iptables Firewall (as root user again)

1. CentOS/Red Hat (RHEL) 6.9

1.1 Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

1.2 Add following INPUT rule:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

1.3 Restart Iptables Firewall:


service iptables restart
## OR ##
/etc/init.d/iptables restart

2. Fedora 26/25/24 and CentOS/Red Hat (RHEL) 7.3

2.1 List Your Active Firewalld Zones


firewall-cmd --get-active-zones

Example output:

public
  interfaces: wlp1s0

2.2 Add New Rule to Firewalld

You might have active zone like public, FedoraWorkstation, FedoraServer.


firewall-cmd --permanent --zone=public --add-service=mysql

## OR ##

firewall-cmd --permanent --zone=public --add --port=3306/tcp

2.3 Restart firewalld.service


systemctl restart firewalld.service

3. Test remote connection


mysql -h 10.0.15.25 -u myusername -p