Red Hat / CentOS

How to Install MySQL on CentOS 8

How to Install MySQL on CentOS 8

MySQL is the most popular open-source relational database management system.

The latest version of the MySQL database server, version 8.0, is available for installation from the default CentOS 8 repositories.

MySQL 8.0 introduced many new features and changes which made some applications incompatible with this version. Before choosing the MySQL version to install, consult the documentation of the application you’re going to deploy on your CentOS server.

CentOS 8 also provides MariaDB 10.3, which is “drop-in replacement” for MySQL 5.7, with some limitations. If your application is not compatible with MySQL 8.0 install MariaDB 10.3.

In this tutorial, we will show you how to install and secure MySQL 8.0 on CentOS 8 systems.


Installing MySQL 8.0 on CentOS 8

Install MySQL from AppStream

With the release of CentOS version 8, many popular software packages were bundled into the AppStream repository.
To install MySQL from AppStream, make sure the repository is enabled first:

# subscription-manager repos ––list-enabled

You should see a list of the different repositories enabled on your system. Check the repo names and make sure that AppStreamis on the list.

Next, use the DNF package manager to install MySQL:

$ sudo dnf install @mysql 

When prompted, type Y and hit Enter to allow the operation to finish.

One advantage of installing MySQL using AppStream is simplicity. However, sometimes the software version in the repositories can be outdated. If you need to install the latest version of MySQL, try installing MySQL from the developer’s repository.

Install MySQL – Developer Community Edition

If you need the latest or a specific version of MySQL, use this step. Often, software developers release newer versions faster than they are uploaded to the default Linux repositories. In this step, we bypass the default repository and install straight from the developer’s repository.

Start by enabling the MySQL developer repository. Enter the following into a terminal window:

# rpm -ivh

Note:  If you need a different version of MySQL, use the actual name of the repository you want to use.  The name can be found on the MySQL Repository Setup Package page.

Verify the repository was correctly added:

# yum repolist all | grep mysql

Temporarily disable the AppStream repository and install MySQL from the developer’s repository:

$ sudo yum ––disablerepo=AppStream install –y mysql-community-server

Allow the process to finish. Re-enable the AppStream repository once finished:

$ sudo yum ––enablerepo=AppStream

Managing the MySQL Service on CentOS 8

Start and Enable MySQL Service

Start the MySQL service:

$ sudo systemctl start mysqld

Set MySQL to start on boot:

$ sudo systemctl enable mysqld

How to Install MySQL on CentOS 8

Stop and Disable MySQL Service

You can stop the MySQL service with the following:

$ sudo systemctl stop mysqld

Prevent the MySQL service from starting at boot:

$ sudo systemctl disable mysqld

Securing MySQL

The default MySQL installation lacks many common security features. It is recommended that you run the secure installation script to enable security features.

These features include removing anonymous user support, disabling remote login, and defining a new MySQL root password.

run the security script by entering the following:

$ sudo mysql_secure_installation

The system will now walk you through your security configuration.

1. You may get a prompt asking if you want to use the VALIDATE PASSWORD PLUGIN. This plugin tests the strength of passwords. We recommend to press Y and specify the level of password validation policy (Low, Medium, or Strong).

2. On the prompt, enter and re-enter a new password for the root MySQL user.

3. When asked if you want to continue using the password you just provided – select Y to set the password.

4. The next prompt asks if you want to remove anonymous users. Y is the setting we recommend.

5. Select Y on the prompt to disallow remote root login. Allowing root access from localhost only is a security best practice.

6.  Type Y to remove the test database. We recommend this setting since anyone can access the test database, and this is why you should remove it from production environments.

7. Finally, enter Y to reload all privilege tables. This action confirms the changes you made.

How to Install MySQL on CentOS 8


In this article, you have learned how to install MySQL 8.0 on CentOS 8 / RHEL 8. Please share your feedback in the comments section.

About the author

Jamie Vadym

Jamie Vadym

Founder of Error Hat. Expertise in Virtualization, Cloud Computing, Linux/UNIX systems, Programming,Storage systems,HA, Server Clustering e.t.c.

Add Comment

Click here to post a comment