Installing MySQL 5.7 on CentOS 7.5
*The Base Image for this tutorial is a Digital Ocean CentOs 7.5 Image with 1GB Memory and 25GB Diskspace.
1. Connecting to your Server
You will need a SSH-Client like Putty if you are coming from Windows. On Unix-OS like OSX and Linux you can use terminal.
After connecting to the server you will be greeted by the following screen:
2. If you are logged in as root, it is highly recommended that you create another account and add this account to the wheel group. To achieve this, you have to type the following on the terminal.
where <username> can be any name you would like to have for the account. For this tutorial, we are going to create the user “corefinity”.
After hitting Enter, you need to assign a password to this user, as it won’t be enabled like in Ubuntu without doing so. To achieve this, you need to type
and repeat the password twice. You now have created your first user.
Unfortunately, this user doesn’t have any root-permissions yet, but we are going to change this now
As we are still logged in as root, we are now going to add our corefinity-user to the group of wheel.
usermod -aG wheel corefinity
will achieve this. We now have a non-root account, which can install software and updates.
To switch to this user, we need to type
and to exit this user and return to root, we just need to type
and hit enter.
3. The first step you will need to do is updating your base image. Under our newly created corefinity-user, we need to type the following:
sudo yum update -y
and run the command by hitting enter. This will update yum’s packages and look similar to the following screenshot.
4. Now it’s time to install MySQL 5.7. First we need to install wget to be able to add the MySQL repository
sudo yum install wget -y
Yum will download the wget-package and install it.
We now need to add the MySQL5.7 repository by typing
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
After this is finished, we can install MySQL5.7 with the following command:
sudo yum install mysql-server –y
After confirming the dependencies with ‘y’ and finishing the installation, we need to enable and start the MySQL-server with
sudo systemctl enable mysqld
sudo systemctl start mysqld
We can now check, if the process was a success with the following command:
sudo systemctl status mysqld
If everything went well, we will see an output similar to the below screenshot:
Now we need to connect to the database. As the installation created a temporary password, we need to get this one first with the following command:
sudo grep ‘temporary password’ /var/log/mysqld.log
This will return the root-password for the database. If you want to connect to your mysql-database now, you can do so by typing
mysql –u root –p
and using the previous temporary password after being prompted.
To disconnect from the database, just type ‘exit’ and hit enter.
Congratulations, you just set up your MySQL 5.7 database on CentOS and took the next step to your own webserver.