MySQL is the world's most popular open source database. With its proven performance, reliability and ease-of-use, MySQL has become the leading database choice for web-based applications. MySQL is a central component of the LAMP open-source web application software stack.

MariaDB is the default package on CentOS 7 which means if you want to install MySQL on CentOS 7 by running the command: yum install mysql, MariaDB would be installed.

In this guide, we will explain how to install the latest version of MySQL on a CentOS 7 server.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Step 1: Adding MySQL Repo
The first step is to add the MySQL community Yum Repo which provides packages for MySQL by visiting the URL below:

 https://dev.mysql.com/downloads/repo/yum/

Locate the desired version. In this guide, we will be installing the MySQL 8.0 version. Proceed to download as shown below

wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

After downloading the rpm file, we need to verify the integrity of the downloaded rpm file by running md5sum and comparing it with the corresponding MD5 value listed on the MySQL page. Type the commands below:

md5sum mysql80-community-release-el7-1.noarch.rpm

After verification, we can now to proceed to install the repo with the command below:

sudo rpm -ivh mysql80-community-release-el7-1.noarch.rpm

This adds two new MySQL yum repositories.

We can now proceed to install MySQL with the command below:

sudo yum install mysql-server

Press y to confirm when prompted. You'll also be prompted to accept the GPG key. Press y to download it and complete the install.

Step 2: Starting MySQL
After the installation has been completed, enable MySQL to start on boot then start the service with the following commands:

sudo systemctl enable mysqld
sudo systemctl start mysqld

To check the status of MySQL, type the following command below:

sudo systemctl status mysqld

During the installation process, a temporary password was generated for the MySQL root user. Type the command below to locate it in the mysqld.log:

sudo grep 'temporary password' /var/log/mysqld.log

You can write down this password somewhere safe as it will be needed in the next steps to secure the installation and where you will be required to change it.

The default password policy requires 12 characters, with at least one uppercase letter, one lowercase letter, one number and one special character.

Step 3: Configuring the MySQL Server
Similar to MariaDB, MySQL includes a security script to change some of the less secure default options for things like remote root logins and sample users. The command is similar to that of MariaDB as shown below:

sudo mysql_secure_installation

This will prompt you for the default root password. As soon as you enter it, you will be required to change it.

Enter a new 12-character password, after which you will be prompted to change it. Type No since you just set it.

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.

Step 4: Testing
After securing the database server, we can verify MySQL is working as needed. Type the command below to check the version installed:

mysqladmin -u root -p version