
How to Install MariaDB 10.3 on CentOS 7: A Step-by-Step Guide
MariaDB is a powerful, open-source relational database management system (RDBMS) that serves as a popular drop-in replacement for MySQL. Known for its performance, stability, and robust feature set, it’s a cornerstone for countless web applications and services.
While CentOS 7 includes a version of MariaDB in its default repositories, it is often an older, outdated version. This guide will walk you through the process of installing the modern MariaDB version 10.3 on your CentOS 7 server, ensuring you have access to the latest features and security enhancements.
Prerequisites
Before we begin, ensure you have the following:
- A server running CentOS 7.
- Access to the command line via a terminal or SSH.
- A user account with
sudo
privileges or direct root access.
Step 1: Add the Official MariaDB Yum Repository
To install a specific version of MariaDB that is not in the default CentOS repositories, we first need to tell our system’s package manager (yum
) where to find it. This is done by creating a new repository file.
Create and open a new file using your preferred text editor, such as nano
or vi
:
sudo vi /etc/yum.repos.d/MariaDB.repo
Now, copy and paste the following configuration into the file. This configuration points yum
to the official MariaDB 10.3 repository.
# MariaDB 10.3 CentOS repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Save the file and exit the editor. Your system is now configured to fetch packages from the correct source.
Step 2: Install MariaDB Server and Client
With the repository in place, the installation process is straightforward. Run the following command to install the MariaDB server, the command-line client, and all necessary dependencies.
sudo yum install MariaDB-server MariaDB-client -y
The -y
flag automatically confirms any prompts, streamlining the installation. The package manager will download and install all the required components.
Step 3: Start and Enable the MariaDB Service
Once the installation is complete, the MariaDB service will not be running by default. We need to start it and then enable it to launch automatically whenever the server reboots.
First, start the MariaDB service with this command:
sudo systemctl start mariadb
Next, enable the service to start on boot:
sudo systemctl enable mariadb
You can verify that the service is running correctly by checking its status:
sudo systemctl status mariadb
You should see an output indicating the service is active (running)
.
Step 4: Secure Your MariaDB Installation
A default MariaDB installation is not secure. Fortunately, it includes a helpful interactive script to lock it down. This is a critical step for any production environment.
Run the security script with the following command:
sudo mysql_secure_installation
The script will guide you through several essential security questions. Here are the recommended answers for a secure setup:
- Enter current password for root (enter for none): Since this is a new installation, there is no password. Just press Enter.
- Set root password? [Y/n]: Type Y and press Enter. You will be prompted to create and confirm a strong password for the database root user.
- Remove anonymous users? [Y/n]: Type Y and press Enter. Anonymous users are a security risk and should be removed.
- Disallow root login remotely? [Y/n]: Type Y and press Enter. This is a vital security measure. It prevents anyone from trying to guess the root password from the network.
- Remove test database and access to it? [Y/n]: Type Y and press Enter. The test database is not needed for a production environment.
- Reload privilege tables now? [Y/n]: Type Y and press Enter. This applies all the security changes you just made immediately.
Your MariaDB installation is now secured against common threats.
Step 5: Verify the Connection
The final step is to confirm that you can log in with the new root user and password you just created. Use the MariaDB client to connect to the database server:
mysql -u root -p
The system will prompt you to Enter password:
. Type the new root password you set during the security script and press Enter.
If the login is successful, you will be greeted with the MariaDB monitor prompt, which looks something like this:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.34-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)]>
To exit the monitor, simply type exit
and press Enter.
Congratulations! You have successfully installed and secured MariaDB 10.3 on your CentOS 7 server. You are now ready to create databases, manage users, and power your applications.
Source: https://kifarunix.com/install-mariadb-10-3-on-centos-7/