## Table of Contents
– [Install MySQL on CentOS 7](#install-mysql-on-centos-7
– [Install MySQL](#install-mysql
– [Start MySQL](#start-mysql
– [Configure MySQL](#configure-mysql
– [Test MySQL](#test-mysql
In this guide, we are going to explain to you how to install MySQL on CentOS 7 and some additional recommended steps that you must take to increase the usability and security of your server.
[MySQL](https://www.mysql.com/ is one of the most popular open-source database management systems in the world. It is commonly installed as a part of the LEMP stack. To manage data, MySQL uses a relational database and a [Structured Query Language (SQL](https://en.wikipedia.org/wiki/SQL.
CentOS 7 prefers [MariaDB](https://mariadb.org/, which is developed by the MySQL developers as a replacement for MySQL. MariaDB will be installed even if you run the yum install mysql command on CentOS 7. So, if you want MariaDB installation for reference, follow our guide, [How to Install MariaDB on CentOS 7](https://systemongrid.com/support/guides/how-to-install-mariadb-on-centos-7. Between MySQL and MariaDB, [MariaDB is the preferable package and can work better](https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/.
Before installing MySQL, you should have access to the CentOS 7 server and created a non-root user account with sudo privileges by following our guide, [Initial server setup with CentOS 7](https://systemongrid.com/support/guides/initial-server-setup-with-centos-7.
## Install MySQL on CentOS 7
## Install MySQL
As we mentioned earlier, MariaDB will be installed even if you run the yum install mysql command on CentOS 7. So, you need to visit the MySQL Yum Repository which provides MySQL packages.
Locate the desired MySQL version and update it using the below command.
$ wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
After saving the rpm file is saved, verify the authenticity of the download using the below the command.
$ md5sum mysql80-community-release-el7-2.noarch.rpm
Verify the above output with the relevant MD5 value on MySQL Yum Repository website.
Once you have verified the file is authentic, install the package.
$ sudo rpm -ivh mysql80-community-release-el7-2.noarch.rpm
The above command adds two MySQL yum repositories, and you can use them to install the MySQL server.
$ sudo yum install mysql-server
Enter “Y” to confirm that you want to continue.
You will also be asked to accept its GPG key. Enter “Y” to confirm that you want to continue.
## Start MySQL
Start the MySQL daemon using the command:
$ sudo systemctl start mysqld
Check the status of the MySQL server.
$ sudo systemctl status mysqld
A temporary password must have generated for the root user. You can locate the password in the mysqld.log.
$ sudo grep ‘temporary password’ /var/log/mysqld.log
## Configure MySQL
MySQL uses a security script to modify the default security options like remote logins. Use the below command to run the security script.
$ sudo mysql_secure_installation
You will be asked to enter the default root password (the temporary password. After this, you will be asked to set a password for the root account. Enter “Y” if you want to set a password. After entering “Y”, you will need to enter a password and confirm it by re-entering the password.
You will get the estimated strength of the password and asked if you wish to continue with the password provided. Enter “Yes” to continue or “No” to enter another strong password.
Then, you will be asked if you want to remove anonymous users. Press Y for yes, or any other key to continue. (We recommend accepting all the below security suggestions by entering “Y” in each step.
Then, you will be asked if you want to disallow root login remotely. Press Y for yes, or any other key to continue.
Then, you will be asked to remove the test database. Press Y for yes, or any other key to continue.
Then, you will be asked to reload privilege tables. Press Y for yes, or any other key to continue.
## Test MySQL
You can test your installation and know the information about it. For that, you need to connect to MySQL as a root user using the below command.
$ mysqladmin -u root -p version
The above output shows that the MySQL installation has been successful.
In this guide, you have learned how to install MySQL on CentOS 7 and some additional recommended steps that must be taken to increase the usability and security of your server.