Let us show you how to install MySQL on your CentOS 7 server. MySQL is a relational database management system that functions through the use of a query system. Created in 1995, it’s an open-source project that is currently developed by Oracle, and has existed since 1995. It’s fast, written in C and C++, and is available on almost any system platform. Its features include cross-platform support, replication support, Unicode support, triggers, cursors, and much more. Since this is such a highly versatile and desirable database-management tool, most people want to install it on their Linux machines, but find that the built-in software repositories install MariaDB, which is a community-developed version of MySQL.
In this tutorial, we will go through the process of installing MySQL 8.0 on CentOS 7, and not MariaDB. It’s simple, but does involve adding a custom repository made by MySQL themselves. For this, you will need an active internet connection, and a VPS or server running CentOS 7.
Table of Contents
Step 1: Download the Yum repository.
In order to add the new repository, we need to download it first. You then need to click on the “Download” button next to the download for Red Hat Enterprise Linux 7. Once the page loads, right-click “No thanks, just start my download” found at the bottom half of the page, and click on “Copy Link” or “Copy Linked Address”.
Now, SSH or log into your CentOS 7 machine, and make sure that you have the “wget” tool installed by just typing “wget” into the bash shell. If you don’t have wget installed, simply install it by entering the following command:
yum install -y wget
Within the next minute, wget will be downloaded and installed onto your system. Once you have wget, you can now download the repository file. Navigate to a folder where you want the download to be saved, and enter the following command:
wget <paste the download link here>
Give it a moment to download and save the file to your machine. When done, proceed to the next step.
Step 2: Add the MySQL Yum repository.
Adding this new repository to your Yum program is very easy. Just enter the following command:
sudo rpm -Uvh <enter the package name here>
Replace <enter the package name here> with the name of your package. You can use the Tab key to autocomplete the entry if you have partially typed it already. Enter your user account’s password when prompted to. Once you have successfully added the Yum repository, proceed to the next step.
Step 3: Install MySQL.
Now that we have the repository added, we can now install the official MySQL software package. Just enter the following command to install:
sudo yum install mysql-community-server
Press the ‘y’ key if prompted to. Within a couple of minutes, the MySQL server will be downloaded and installed onto your CentOS 7 system.
Step 4: Set up MySQL.
You now HAVE to start the server and set the root password. First, start your MySQL server by executing the following command:
sudo systemctl start mysqld.service
When this is done for the first time, the root user is created with a random password, and the password can be found in the error log file. Use this next command to reveal the password:
sudo grep ‘temporary password’ /var/log/mysqld.log
the output should contain the password itself. Now you need to log in as the root user using this password. Enter this next command to enter the MySQL query shell:
mysql -uroot -p
Enter the password you just read from the output. Once you have logged in, change the root password by entering the following command (NOTE: Don’t forget to change ‘mypassword’ to the password you wish to use! Your password must be at least 8 characters long, and contain an uppercase letter, a lowercase letter, a special character, and at least one digit. ):
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mypassword';
You have now successfully set your new root account password.
If you ever need to update your MySQL server, just do it though Yum by simply upgrading the package:
sudo yum update mysql-server
This update process also happens when you update the entire system using Yum. Once the server is updated, it automatically restarts, it is important to run “mysql_upgrade” in order to have MySQL perform check with its plugins to make sure that everything will continue to run smoothly.
If you need your MySQL server to run every time you boot the machine up, enter the following command:
sudo systemctl enable mysqld.service
Now when you restart your machine, your MySQL server will be automatically started.
If you have followed this tutorial correctly, your CentOS 7 machine should now have a copy of MySQL server running on it. From here, you can work with databases, add plugins and extensions to make working with these databases easier, and so on.
Of course, you don’t need to install MySQL on your CentOS 7 server yourself if you have a CentOS VPS hosted with us – in which case, our technical support team will install MySQL and set it up for you. They are available 24/7, and can cater to any questions or requests.
PS. If you liked this post, feel free to share it with your friends by using the social media share shortcuts below, or simply leave a comment. Thanks.