Support Online
Skip to main content

How to Install MySQL (CentOS)? -- MySQL 8 Guide

Meta Description: Learn step by step how to install MySQL 8, add official repositories and security settings on CentOS 7 and CentOS Stream systems.

What will you learn in this guide?

In this content, you will learn how to install MySQL 8 on CentOS.
You will install Oracle MySQL instead of the default MariaDB.
After installation, you will complete the security and verification steps.

Technical Summary

On CentOS systems, the yum install mysql command installs MariaDB.
This guide takes you through a real MySQL 8 installation by adding the official MySQL community repository.
Steps: adding repository, package installation, service startup, security setting and testing.


Requirements

  • CentOS or RHEL based server\
  • sudo authorized user

Note: CentOS 7 and 8 have completed their lifecycle. CentOS Stream is recommended for production.


1️⃣ Adding MySQL Official Repository

Check the system version first:

cat /etc/os-release

This command shows the operating system version.

Download the official MySQL 8 repository package (example el7):

curl -sSLO https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm

This command downloads the MySQL repository package.

Check file integrity:

md5sum mysql80-community-release-el7-5.noarch.rpm

This command checks the authenticity of the downloaded file.

Add the repository to the system:

sudo rpm -ivh mysql80-community-release-el7-5.noarch.rpm

This process identifies the MySQL official package source.


2️⃣ MySQL Server Installation

For CentOS 7:

sudo yum install mysql-server

This command installs the MySQL server.

For CentOS Stream 9:

sudo dnf install mysql-server

This command installs with the new package manager.

The GPG key is confirmed during installation. Press y.


3️⃣ Starting MySQL Service

Start the service:

sudo systemctl start mysqld

This command runs the MySQL service.

Check the status:

sudo systemctl status mysqld

Verifies that the service is active.

To turn off autostart:

sudo systemctl disable mysqld

This command disables startup at startup.


4️⃣ Learning Temporary Root Password

A temporary password is created after installation:

sudo grep 'temporary password' /var/log/mysqld.log

This command shows the temporary root password.


5️⃣ MySQL Security Configuration

Run the security tool:

sudo mysql_secure_installation

This command configures basic security settings.

What you need to do:

  • Change root password\
  • Delete anonymous users\
  • Turn off remote root access\
  • Remove test database\
  • Refresh authorization tables

The password must be at least 12 characters.
It must contain uppercase letters, lowercase letters, numbers and special characters.


6️⃣ Testing the Installation

Check version information:

mysqladmin -u root -p version

This command shows the MySQL version and uptime.

If version information is visible, the installation is successful.


Frequently Asked Questions (FAQ)

Why does mysql command install MariaDB?

CentOS defaults to MariaDB instead of MySQL.

Do MySQL and MariaDB run at the same time?

Not recommended. They share port 3306.

I'm using CentOS Stream, do the commands change?

Yes. You should use dnf instead of yum.

Why isn't my password accepted?

MySQL 8 enforces a strong password policy.

I get a connection error after installation, why?

The service may not be working.
Check with systemctl status mysqld.


Result

With this guide, you have completed the MySQL 8 installation on CentOS.
You have added the official repository and made secure configuration.

In the next step:

  • You can proceed to the MySQL user and permission management guide.\
  • You can make a full LEMP installation by installing Nginx and PHP.

You can try GenixNode infrastructure immediately for your high-performance projects.