As of CentOS 7 the default database is MariaDB and a drop in replacement for MySQL and should be fine for most people but if you need MySQL, there are some features in MySQL and not in MariaDB and vice versa.

So with that said following these steps should get you MySQL installed in no time! If you are OK with MariaDB then you can follow steps 2 – 3 only and this will install MariaDB.

Step 1 – Install MySQL Repository:

First we have to install the community repository with

to download the repository then

Step 2 – Install MySQL:

to install it. Now we have to update yum with

Once this is done we can install mysql client and server with

and now start MySQL with

Step 3 – Secure MySQL:

Now we have MySQL installed and started we have to secure it by setting the root password, removing anonymous user accounts, disable the root login outside of localhost and remove the test databases. we do this with

and you will be presented with this

If you have had MySQL installed before then enter the root password here but if this is a clean install just press enter the next question will be

We want to set a password for root so answer ‘y’ and add your password. After you have set your password you will be asked

We want to answer yes as we don’t want anonymous users next question will be

We again want to answer ‘y’ to this as we don’t want root to be accessed from the outside world! Next we have

We answer ‘y’ again as we do not want the test databases left installed, we have no need of them and finally

we will be asked to reload the privilege tables which we do want to so ‘y’ again.

With that done we can test our MySQL by logging into the mySQL shell with

enter your password and you should see

Now we have MySQL 5.6.35 installed. Enter ‘q’ and press enter to quit the MySQL shell.

Step 4 – Updating to MySQL 5.7.x

As of writing this MySQL 5.7.x was released but this repo has has that turned off so the update MySQL to 5.7.x first we enable it by

the entry we are looking is

Change the ‘enabled=0’ to ‘enabled=1’ like

Save and exit the editor and the update yum with

Yum should now update MySQL to version 5.7.x totes this enter the MySQL shell again with

and you should see some like this

And that’s it we have now installed MySQL 5.7.x

Watch on YouTube: Installing MySQL on CentOS 7