How to Install MySQL on CentOS 8

Install MySQL on CentOS 8

In this article, we will have explained the necessary steps to install and configure MySQL on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

MySQL is the most popular open-source relational database management system. It supports both SQL and NoSQL and has a pluggable storage engine architecture. Additionally, it also comes with multiple database connectors for different programming languages, allowing you to develop applications using any of the well-known languages, and many other features.


  • Operating System with CentOS 8
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install MySQL on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum install epel-release
sudo yum update

Step 2. Installing MySQL on CentOS.

Install the MySQL package with the following command:

sudo dnf install @mysql

To start and enable PostgreSQL you need to use the systemctl command:

sudo systemctl enable --now mysqld
sudo systemctl status mysqld

Step 3. Secure MySQL server.

You should now run mysql_secure_installation to configure security for your MySQL server:

sudo mysql_secure_installation

Then enter YES/Y to the following security questions:

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

As a test, you can log into the MySQL server and run the version command:

mysql -u root -p

Enter the root password when prompted, and you will be presented with the MySQL shell as shown below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.17 Source distribution

Congratulation, you have learned how to install and configure MySQL on CentOS 8. If you have any question, please leave a comment below.