Cài mariadb centos 7

  • Prerequisites

    To follow this tutorial, you will need:

    • A CentOS 7 with a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in the Initial Server Setup with CentOS 7 guide.

    Step 1 — Installing MariaDB

    We’ll use Yum to install the MariaDB package, pressing y when prompted to confirm that we wish to proceed:

    • sudo yum install mariadb-server

    Once the installation is complete, we’ll start the daemon with the following command:

    • sudo systemctl start mariadb

    systemctl doesn’t display the outcome of all service management commands, so to be sure we succeeded, we’ll use the following command:

    • sudo systemctl status mariadb

    If MariaDB has successfully started, the output should contain “Active: active (running)` and the final line should look something like:

    • Dec 01 19:06:20 centos-512mb-sfo2-01 systemd[1]: Started MariaDB database server.

    Next, let’s take a moment to ensure that MariaDB starts at boot, using the systemctl enable command, which will create the necessary symlinks.

    • sudo systemctl enable mariadb
    Output
    Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
    

    Next, we’ll turn our attention to securing our installation.

    Step 2 — Securing the MariaDB Server

    MariaDB includes a security script to change some of the less secure default options for things like remote root logins and sample users. Use this command to run the security script:

    • sudo mysql_secure_installation

    The script provides a detailed explanation for every step. The first prompts asks for the root password, which hasn’t been set so we’ll press ENTER as it recommends. Next, we’ll be prompted to set that root password, which we’ll do.

    Then, we’ll accept all the security suggestions by pressing Y and then ENTER for the remaining prompts, which will remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables.

    Finally, now that we’ve secured the installation, we’ll verify it’s working.

    Step 3 — Testing the Installation

    We can verify our installation and get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the following command to connect to MariaDB as root (-u root), prompt for a password (-p), and return the version.

    • mysqladmin -u root -p version

Leave a Reply

You must be logged in to post a comment.