Tutorial on installing and configuring MariaDB on CentOS 7

MariaDB is an open source, legacy-compatible relational database management system, and is a binary alternative to MySQL. MariaDB is developed by some of the original MySQL developers and many from the open source community. With the release of CentOS 7, MySQL has been replaced by MariaDB as the default database system.

If, for some reason, you want to install MySQL instead of MariaDB, check out our tutorial How to Install MySQL on CentOS 7. If your system doesn’t have any specific recommendation requirements, it’s a good idea to stick with MariaDB, which by the way is the default database system on CentOS 7.

In this tutorial we will show you how to install the latest version of MariaDB on CentOS 7 using the official MariaDB repository.

precondition

Make sure you are logged in as a user with sudo privileges before proceeding with the tutorial.

Install MariaDB 5.5 on CentOS 7

The MariaDB server version available in the default CentOS repository is version 5.5. It’s not the latest version, but it’s stable enough for productivity.

Follow the steps below to install and secure MariaDB 5.5 on CentOS 7:

  1. Install MariaDB package using package manager yum:
    sudo yum install mariadb-server

    He presses y When prompted to continue with the installation.

  2. Once the installation is complete, start the MariaDB service and enable it to start automatically on boot with the following command:
    sudo systemctl start mariadb 
    
    sudo systemctl enable mariadb
  3. To verify that the installation was successful, check the status of the MariaDB service by typing:
    sudo systemctl status mariadb

    The output will show that the service is running:

  4. Run the script mysql_secure_installation Which will perform several security related tasks:
    sudo mysql_secure_installation

    You will be prompted to set the root user password, remove anonymous user accounts, restrict root user access to the local machine, and delete the test database.

    The steps are explained in detail. It is desirable that you answer Y (Yes) to all questions.

See also  Customize Linux Terminal with Tmux

Install MariaDB 10.3 on CentOS 7

At the time of writing this article, the latest version of MariaDB is version 10.3. If you need to install another version of MariaDB, go to the MariaDB repository page, and create a repository file for the specific MariaDB version.

To install MariaDB 10.3 on CentOS 7, follow these steps:

  1. The first step is to enable the MariaDB repository. Create a repository file named MariaDB.repo And add the following content:
    # MariaDB 10.3 CentOS repository list - created 2018-05-25 19:02 UTC
    # 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
  2. Install the MariaDB server and MariaDB client packages using yumjust like any other CentOS package installation:
    sudo yum install MariaDB-server MariaDB-client

    Yum Package Manager may prompt you to import the MariaDB GPG key:

    Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    Importing GPG key 0x1BB943DB:
     Userid     : "MariaDB Package Signing Key <[email protected]>"
     Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
     From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    Writes y and press Enter

  3. Once the installation is complete, enable MariaDB to boot and start the service:
    sudo systemctl enable mariadb
    
    sudo systemctl start mariadb
  4. To verify the installation, check the status of the MariaDB service by typing:
    sudo systemctl status mariadb
    ● mariadb.service - MariaDB 10.3.7 database server
       Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/mariadb.service.d
               └─migrated-from-my.cnf-settings.conf
       Active: inactive (dead)
         Docs: man:mysqld(8)
               https://mariadb.com/kb/en/library/systemd/
  5. The last step is to run the script mysql_secure_installation Which will perform several security related tasks:
    sudo mysql_secure_installation

    The script will prompt you to set the root user password, remove anonymous users, restrict root user access to the local machine, and delete the test database.

    All steps are explained in detail and an answer is suggested Y (Yes) to all questions.

See also  How to install LibModsecurity WAF app on Nginx CentOS 8

Connect to MariaDB from the command line

To connect to a MariaDB server via the device as root account type:

mysql -u root -p

You will be prompted to enter the root password that you set earlier during the scriptmysql_secure_installation Being.

After entering the password, you will be presented with MariaDB shell as shown below:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.7-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.

conclusion

In this tutorial, we show you how to install and secure MariaDB on a CentOS 7 server.

To better understand how to administer and manage MariaDB databases, see also other guides on managing and managing databases:

  • Manage MySQL database using command line
  • Tutorial How to reset MySQL root password
  • How to create a MySQL database on Linux Terminal
  • How to create a MySQL user and MySQL access rights
  • How to show all users in MySQL
  • Mysqldump Tutorial for MySQL Database Backup and Restore

Source link