How to Install MariaDB in RHEL and Debian Systems

MariaDB is a binary drop-in replacement for MySQL, developed by the original authors of MySQL Project and fully compatible with MySQL having more features and better performance enhancement.

Why should I Use MariaDB?

As we all know MySQL is widely used and the most popular RDBMS and the first choice of developers. In 2008, MySQL was acquired by Sun Microsystem, which was subsequently bought by Oracle and is no longer open source.

Well, MariaDB is sponsored by Monty Program AB & MariaDB Foundation and is independently developed by the core developer of MySQL and other community members, and is truly open source.

MySQL was created by MichaelMontyWidenius, David Axmark, and Allan Larsson the founder of MySQL, and Monty Program AB is now behind MariaDB. They would oversee the development of the MariaDB foundation.

Who uses MariaDB?

There are a number of distributions & large websites that have switched to MariaDB, some of them are:

  • Google
  • Amazon Web Services
  • Facebook
  • Mozilla Corporation
  • Wikipedia
  • OpenSuse
  • Fedora
  • OLX
  • Nimbuzz
  • SlashGear
  • ArchLinux
  • Redhat Enterprise Linux (from RHEL7)
  • Manjaro
  • Mageia
  • Debian
  • The Chakra Project
  • Gentoo
  • OpenBSD

Installing MariaDB in RHEL-based Distributions

On RHEL-based distributions such as CentOS Stream, Rocky Linux, and AlmaLinux, it is strongly recommended to install the appropriate RPM packages from AppStream’s repository using yum or dnf as shown.

# yum install mariadb-server mariadb-backup mariadb-common
OR
# dnf install mariadb-server mariadb-backup mariadb-common
Install MariaDB in RHEL
Install MariaDB in RHEL

Once the installation is complete, you can start, enable and verify the status of the MariaDB service with:

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
Check MariaDB in RHEL
Check MariaDB in RHEL

Once the MariaDB service is started, it is time to enhance its security by setting a root password, removing anonymous users, disabling remote root login, removing the test database, and reloading privilege.

# mysql_secure_installation

It is noted that the root password is empty, so if you want to set it, simply press “enter”, when prompted and set the root password. For the rest you can follow the steps and answers on the image below:

Secure MariaDB in RHEL
Secure MariaDB in RHEL

Once the MariaDB is secured, it is time to connect to the mysql shell as shown.

# mysql -u root -p 

When prompted, enter the root password that you set earlier.

Installing MariaDB in Debian-based Distributions

On Debian-based distributions such as Ubuntu and other similar Linux distributions, it is strongly recommended to install the appropriate DEB packages from MariaDB’s repository using the apt package manager.

# apt install mariadb-server mariadb-backup mariadb-common
Or
$ sudo apt install mariadb-server mariadb-backup mariadb-common
Install MariaDB in Debian
Install MariaDB in Debian

Once the installation is complete, you can start, enable and verify the status of the MariaDB service with:

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
Check MariaDB in Debian
Check MariaDB in Debian

Once the MariaDB service is started, it is time to enhance its security by setting a root password, removing anonymous users, disabling remote root login, removing the test database, and reloading privilege.

# mysql_secure_installation
Secure MariaDB in Debian
Secure MariaDB in Debian

Login to MariaDB with the root credential which was set earlier.

$ sudo mysql -u root -p
[sudo] password for narad: 
Enter password:
Connect MariaDB in Debian
Connect MariaDB in Debian

Type quit from the command prompt to exit from the database.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Narad Shrestha
He has over 10 years of rich IT experience which includes various Linux Distros, FOSS and Networking. Narad always believes sharing IT knowledge with others and adopts new technology with ease.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

11 thoughts on “How to Install MariaDB in RHEL and Debian Systems”

  1. Please do the followings:-

    1. Stop MariaDB
    2. Copy the existing data directory i.e. /var/lib/mysql (default location) to new location
    3. Edit the MariaDB configuration file.
    4. Search entry for datadir or create the new one as below.

    datadir = /newpath

    5. Restart mariadb service.

    Reply
      • My installation is centos 6.5 and MariaDB 10.07

        I use mariadb over a year on my notebook (fedora 19, and currently mariadb 5.5). On the notebook I changes the data directory to /home/db/mariadb by changing in /etc/my.cnf datadir=/var/lib/mysql to datadir=/home/db/mariadb. After restart of mysqld it works fine and all my data resides in that directory.

        In the instant case /etc/my.cnf does not contain any data. Likewise the sample cnf file do not have an entry for datadir. Once the parameter datadir is entered the server starts but complains, in my case, on write error due to inability to access /var/lib/mysql/[my server name].pid.

        Can you please suggest how to change datadir on Centos 6.5 with MariaDB 10.07. If I live the deafault of /var/lib/mysql, every thing works fine.

        Reply
  2. i got this error after replacing default installed MariaDB to MYSQL in my Fedora 19

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

    I tried installing MariaDB again but i still got the error (after removing mysql server)

    Reply
    • Check your mysql daemon is running if not start with below command.

      Start the mysqld daemon.
      # systemctl start mysqld

      To enable mysql daemon to start at boot
      # systemctl enable mysqld.service

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.