How To Install MySQL / MariaDB on CentOS 7

Try it in our public cloud & Get $5 Credit

How To Install MySQL / MariaDB on CentOS 7

CentOS 7 does not use the regular Oracle MySQL when installing from yum. Instead, it installs a fork called MariaDB. For most users, this is not an issue as it offers a very similar feature set to the current MySQL releases. However, if you would prefer to install the MySQL as offered by Oracle, you will need to use the official MySQL repository. You can find the knowledge base for oracle MySQL here. However, this guide will show you how to install MariaDB, the default MySQL version for CentOS 7.


To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Servers) with CentOS 7 installed

Install MySQL / MariaDB

First, you need to install the package. As said previously, writing MySQL in yum will redirect to the MariaDB packages. However, this will only install the client and not the server. This is not what we want, so we need to specify the proper package names.

yum install –y mariadb mariadb-server

Once this is installed, you will want to start it.

systemctl start mariadb

To enable it at startup, run this command:

systemctl enable mariadb

Now that we have the server running, we will want to secure it. We can do so by running the secure installation script.


Here, you will want to set a root password. It is then recommended to remove anonymous users, disallow remote root login, remove the test database and reload the privileges table.

You can now login in command line with the regular MySQL login command:

mysql –u root -p


Maria DB is now setup for production and fully working. You can start using it with most applications that are compatible with MySQL as a database backend. If this guide was helpful to you, kindly share it with others who may also be interested.