Install MariaDB 10.4 on Fedora 31/30, CentOS/RHEL 8.0/7.7/6.10

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.4.8 [stable] or 10.3.18 [stable] on Fedora 31/30/29/28, CentOS 8.0/7.7/6.10 and Red Hat (RHEL) 7.7/6.10. 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.4.8/10.3.18 on Fedora 31/30/29/28, CentOS 7.7/6.10, Red Hat (RHEL) 7.7/6.10

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 30/29/28

Note: currently Fedora 31/30/29 users can install 10.3 and Fedora 28/27 users can install MariaDB 10.2 and not additional repos needed or alternatively use MariaDB repos to install MariaDB 10.4/10.3 (or development) versions or Galera Cluster.

3. Update or Install MariaDB 10.4/10.3

Fedora 31/30/29/28 (Fedora own packages)

dnf install mariadb mariadb-server

CentOS/Red Hat (RHEL) 8.0/7.7/6.10 (and Fedora 31/30/29/28 using MariaDB repos)

yum install MariaDB MariaDB-server

4. Start MariaDB server and autostart MariaDB on boot

Fedora 31/30/29/28 and CentOS/RHEL 8.0/7.7

systemctl start mariadb.service ## use restart after update

systemctl enable mariadb.service

CentOS 6.10 and Red Hat (RHEL) 6.10

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




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
  • PASSWORD = password123

MariaDB [(none)]> CREATE DATABASE webdb;

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

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

##  FLUSH PRIVILEGES, Tell the server to reload the grant tables  ##

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

1. Fedora 31/30/29/28 and CentOS/Red Hat (RHEL) 8.0/7.7

1.1 List Your Active Firewalld Zones

firewall-cmd --get-active-zones

Example output:

  interfaces: wlp1s0

1.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

1.3 Restart firewalld.service

systemctl restart firewalld.service

2. CentOS/Red Hat (RHEL) 6.10

2.1 Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

2.2 Add following INPUT rule:

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

2.3 Restart Iptables Firewall:

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

3. Test remote connection

mysql -h -u myusername -p

36 comments on “Install MariaDB 10.4 on Fedora 31/30, CentOS/RHEL 8.0/7.7/6.10

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.