More

    Install MariaDB on Linux

    Introduction

    When it comes to open-source relational database management systems, MariaDB stands out as a powerful and flexible option. It’s a fork of MySQL and is known for its speed, reliability, and ease of use. If you’re looking to set up MariaDB on a Linux system – RHEL, CentOS, Rocky Linux or Debian, then you’re in the right place. In this step-by-step guide, we’ll walk you through on how to install MariaDB on Linux and how to get you up and running with MariaDB.

    Prerequisites

    Before we dive into the installation process, make sure you have the following:

    1. A Linux-based operating system (e.g., RHEL, CentOS, Rocky, Ubuntu, Debian).
    2. Root or sudo access to your Linux server.

    Step 1: Update Your System

    It’s always a good practice to ensure your system is up-to-date before installing any new software. Open your terminal and run the following commands:

    For Debian/Ubuntu-based systems:

    sudo apt update
    sudo apt upgrade

    For CentOS/RHEL-based systems:

    sudo yum update

    Step 2: Install MariaDB

    Now, let’s proceed with the installation of MariaDB. The command to install it varies slightly depending on your Linux distribution.

    For Debian/Ubuntu-based systems:

    sudo apt install mariadb-client mariadb-server

     

    For CentOS/RHEL-based systems:

    The mariadb package is available in the AppStream repository hence we dont need to setup up the mariaDB repo separately. The module can be installed by running the command:

    dnf install mariadb mariadb-server
    
    Last metadata expiration check: 0:15:29 ago on Thu 31 Aug 2023 12:37:29 PM EAT.
    Dependencies resolved.
    ======================================================================================================================================================================================================================
     Package                                                       Architecture                              Version                                                   Repository                                    Size
    ======================================================================================================================================================================================================================
    Installing:
     mariadb                                                       x86_64                                    3:10.5.16-2.el9_0                                         appstream                                    1.6 M
     mariadb-server                                                x86_64                                    3:10.5.16-2.el9_0                                         appstream                                    9.4 M
    Installing dependencies:
     mariadb-common                                                x86_64                                    3:10.5.16-2.el9_0                                         appstream                                     31 k
     mariadb-connector-c                                           x86_64                                    3.2.6-1.el9_0                                             appstream                                    195 k
     mariadb-connector-c-config                                    noarch                                    3.2.6-1.el9_0                                             appstream                                    9.8 k
     mariadb-errmsg                                                x86_64                                    3:10.5.16-2.el9_0                                         appstream                                    215 k
     mysql-selinux                                                 noarch                                    1.0.5-1.el9_0                                             appstream                                     35 k
     perl-DBD-MariaDB                                              x86_64                                    1.21-16.el9_0                                             appstream                                    151 k
     perl-DBI                                                      x86_64                                    1.643-9.el9                                               appstream                                    700 k
     perl-File-Copy                                                noarch                                    2.34-480.el9                                              appstream                                     20 k
     perl-Math-BigInt                                              noarch                                    1:1.9998.18-460.el9                                       appstream                                    188 k
     perl-Math-Complex                                             noarch                                    1.59-480.el9                                              appstream                                     47 k
     perl-Sys-Hostname                                             x86_64                                    1.23-480.el9                                              appstream                                     17 k
    Installing weak dependencies:
     mariadb-backup                                                x86_64                                    3:10.5.16-2.el9_0                                         appstream                                    6.4 M
     mariadb-gssapi-server                                         x86_64                                    3:10.5.16-2.el9_0                                         appstream                                     19 k
     mariadb-server-utils                                          x86_64                                    3:10.5.16-2.el9_0                                         appstream                                    213 k
    
    
    ...
    
    Installed:
      mariadb-3:10.5.16-2.el9_0.x86_64                        mariadb-backup-3:10.5.16-2.el9_0.x86_64             mariadb-common-3:10.5.16-2.el9_0.x86_64                mariadb-connector-c-3.2.6-1.el9_0.x86_64        
      mariadb-connector-c-config-3.2.6-1.el9_0.noarch         mariadb-errmsg-3:10.5.16-2.el9_0.x86_64             mariadb-gssapi-server-3:10.5.16-2.el9_0.x86_64         mariadb-server-3:10.5.16-2.el9_0.x86_64         
      mariadb-server-utils-3:10.5.16-2.el9_0.x86_64           mysql-selinux-1.0.5-1.el9_0.noarch                  perl-DBD-MariaDB-1.21-16.el9_0.x86_64                  perl-DBI-1.643-9.el9.x86_64                     
      perl-File-Copy-2.34-480.el9.noarch                      perl-Math-BigInt-1:1.9998.18-460.el9.noarch         perl-Math-Complex-1.59-480.el9.noarch                  perl-Sys-Hostname-1.23-480.el9.x86_64           
    
    

     

    Check MariaDB version

    Option1 – rpm

    Check the version that has been installed using the following command:

    rpm -qi mariadb-server
    
    
    Name        : mariadb-server
    Epoch       : 3
    Version     : 10.5.16
    Release     : 2.el9_0
    Architecture: x86_64
    Install Date: Thu 31 Aug 2023 12:53:28 PM EAT
    Group       : Unspecified
    Size        : 65281392
    License     : GPLv2 and LGPLv2
    Signature   : RSA/SHA256, Tue 09 Aug 2022 09:18:19 PM EAT, Key ID 702d426d350d275d
    Source RPM  : mariadb-10.5.16-2.el9_0.src.rpm
    Build Date  : Tue 09 Aug 2022 07:45:12 PM EAT
    Build Host  : pb-04f2ad6b-18d4-474f-a9fa-008b29b9d20d-b-x86-64
    Packager    : Rocky Linux Build System (Peridot) <[email protected]>
    Vendor      : Rocky Enterprise Software Foundation
    URL         : http://mariadb.org
    Summary     : The MariaDB server and related files
    Description :
    MariaDB is a multi-user, multi-threaded SQL database server. It is a
    client/server implementation consisting of a server daemon (mariadbd)
    and many different client programs and libraries. This package contains
    the MariaDB server and some accompanying files and directories.
    MariaDB is a community developed fork from MySQL.

     

    Option2 – mysqladmin

    There is another option to check the running version using the mysqladmin tool which is a mariaDB/MySQL client that lets you run administrative commands. The command connects to MariaDB as root using the Unix socket and returns the version:

    sudo mysqladmin version
    
    mysqladmin  Ver 9.1 Distrib 10.5.16-MariaDB, for Linux on x86_64
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Server version		10.5.16-MariaDB
    Protocol version	10
    Connection		Localhost via UNIX socket
    UNIX socket		/var/lib/mysql/mysql.sock
    Uptime:			9 hours 38 min 21 sec
    
    Threads: 1  Questions: 21  Slow queries: 0  Opens: 20  Open tables: 13  Queries per second avg: 0.000

    An alternative to this is to log in to the MariaDB and check the version:

    sudo mysqladmin -u root -p version
    
    Enter password: 
    mysqladmin  Ver 9.1 Distrib 10.5.16-MariaDB, for Linux on x86_64
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Server version		10.5.16-MariaDB
    Protocol version	10
    Connection		Localhost via UNIX socket
    UNIX socket		/var/lib/mysql/mysql.sock
    Uptime:			9 hours 44 min 9 sec
    
    Threads: 1  Questions: 22  Slow queries: 0  Opens: 20  Open tables: 13  Queries per second avg: 0.000

     

    Step 3: Start and Enable MariaDB

    After the installation is complete, you need to start MariaDB and enable it to start at boot time. Use the following command:

    sudo systemctl enable --now mariadb
    

     

    Step 4: Secure Your MariaDB Installation

    MariaDB provides a script to enhance the security of your installation. Run the following command and follow the on-screen prompts:

    sudo mysql_secure_installation
    
    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
    haven't set the root password yet, you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password or using the unix_socket ensures that nobody
    can log into the MariaDB root user without the proper authorisation.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Switch to unix_socket authentication [Y/n] n
     ... skipping.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Change the 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!

     

    This script allows you to:

    1. set a root password
    2. remove anonymous users
    3. disallow root login remotely
    4. more…

    It’s essential to secure your database to prevent unauthorized access.

    Step 5: Test Your MariaDB Installation

    After ensuring that MariaDB is installed and running correctly, you can log in to the MariaDB shell using the following command. You will be prompted to enter the root password you set earlier:

    sudo mysql -u root -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 11
    Server version: 10.5.16-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> SELECT VERSION();
    +-----------------+
    | VERSION()       |
    +-----------------+
    | 10.5.16-MariaDB |
    +-----------------+
    1 row in set (0.000 sec)
    
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.001 sec)
    
    MariaDB [(none)]> 
    

     

    Congratulations! You have successfully installed MariaDB on your Linux system. You are now ready to create databases, tables, and start building your applications with this powerful open-source database management system.

     

    Conclusion

    In this guide, we’ve walked you through the process of installing MariaDB on a Linux-based system. We are working to create more content on MariaDB. Stay connected.

     

    Read more:

    1. How to Install MongoDB 6.0 on Rocky Linux, Red Hat Enterprise Linux, CentOS Stream, Alma Linux or Oracle Linux
    2. How to Create MongoDB database with the CLI

     

    Recent Articles

    Related Articles

    Leave A Reply

    Please enter your comment!
    Please enter your name here