;

How to Install MySQL on CentOS 7

Try it in our public cloud & Get $5 Credit
CLAIM NOW

MySQL has been around for quite a while. It’s a popular relational database management system that exists since 1995. The following article will guide you on how to install MySQL standard release on CentOS 7.

On CentOS 7, the official Oracle MySQL server is not available by default through the package manager. This is because Redhat decided to go with MariaDB as the official MySQL fork for CentOS 7. If you would prefer to use MariaDB, you can find the procedure here. If you prefer to proceed with Oracle’s official packages, please keep reading.

Getting Started

To complete this guide, you will need the following:

• 1 Node (Cloud Server or Dedicated Servers) with CentOS 7 installed

Install MySQL

First, we will need to add the Oracle MySQL repository to yum. You can do that by acquiring the rpm for the repository and installing it on the server. For the MySQL 5.7 repository, you can issue the following command:

yum install wget
wget https://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum localinstall mysql57-community-release-el7-7.noarch.rpm

Once that’s done, installing MySQL is only a matter of running the yum command with the package name:

yum install mysql-community-server

You will then want to start the service:

systemctl start mysqld

To enable the service on-boot:

systemctl enable mysqld

This version of Oracle MySQL sets a root password by default. We need to retrieve it from the mysql logs.

cat /var/log/mysqld.log
2016-03-10T18:12:07.496135Z 1[Note] A temporary password is generated forroot@localhost: *password*

With that password retrieved, we can now login. First though, let’s run the mysql_secure_installation script.

mysql_secure_installation

Here, you will want to set a new root password. It is then recommended to remove anonymous users, disallow remote root login, remove the test database and reload the privileges table. Once this is done, you can now access MySQL using the usual command line interface.

mysql –u root -p

Conclusion

Your MySQL server is ready for production usage. You can now link your application to it and start using your new MySQL backend. If this guide was helpful to you, kindly share it with others who may also be interested.