How to Install MySQL on RHEL 9 / Rocky Linux 9

Master MySQL installation on RHEL 9 / Rocky Linux 9 with this comprehensive guide, ensuring a robust and secure database setup.

MySQL is one of the most popular relational database management systems, widely used for web applications and various other data-driven applications. Installing MySQL on RHEL 9 or Rocky Linux 9 involves several steps to ensure a secure and optimized database environment. This guide provides a step-by-step walkthrough to install, configure, and secure MySQL on your RHEL 9 or Rocky Linux 9 system.

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Step 1: Update Your System
  4. Step 2: Add the MySQL Repository
  5. Step 3: Install MySQL
  6. Step 4: Start and Enable MySQL Service
  7. Step 5: Secure MySQL Installation
  8. Step 6: Verify MySQL Installation
  9. Step 7: Basic MySQL Configuration
  10. Conclusion
  11. References

Introduction

MySQL is a powerful and reliable database system that is essential for many applications. Whether you're setting up a web server or developing software that requires a database, knowing how to install and configure MySQL on RHEL 9 or Rocky Linux 9 is crucial. This guide will cover all necessary steps to get MySQL up and running on your system, ensuring it's secure and ready for use.

Prerequisites

Before starting, ensure you have:

  • A system running RHEL 9 or Rocky Linux 9.
  • A user account with sudo privileges.
  • Internet access to download necessary packages.

Step 1: Update Your System

It’s important to start by updating your system to ensure all existing packages are up-to-date. Open your terminal and run the following commands:

sudo dnf update -y sudo dnf upgrade -y

This will update your package lists and install the latest versions of all packages.

Step 2: Add the MySQL Repository

MySQL is not included in the default RHEL 9 / Rocky Linux 9 repositories. You need to add the MySQL YUM repository.

  1. Download the MySQL repository package:

    wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm

  2. Install the repository package:

    sudo rpm -Uvh mysql80-community-release-el9-1.noarch.rpm

  3. Verify the repository is added:

    sudo dnf repolist all | grep mysql

Step 3: Install MySQL

With the repository added, you can now install MySQL.

  1. Install MySQL server:

    sudo dnf install mysql-server -y

  2. Confirm the installation:

    mysql --version

This command should return the version of MySQL installed on your system.

Step 4: Start and Enable MySQL Service

To start using MySQL, you need to start the MySQL service and enable it to start on boot.

  1. Start the MySQL service:

    sudo systemctl start mysqld

  2. Enable the MySQL service to start on boot:

    sudo systemctl enable mysqld

  3. Check the status of MySQL service:

    sudo systemctl status mysqld

This command should show that the MySQL service is active and running.

Step 5: Secure MySQL Installation

MySQL provides a security script to help secure your installation. Run the following command to start the script:

sudo mysql_secure_installation

You will be prompted to configure the VALIDATE PASSWORD PLUGIN and other security options, such as setting a root password, removing anonymous users, disabling root login remotely, and removing the test database. Follow the prompts and choose appropriate security settings for your installation.

Step 6: Verify MySQL Installation

To verify the installation and check that MySQL is working correctly, log in to the MySQL server as the root user:

sudo mysql -u root -p

Enter the root password you set during the mysql_secure_installation process. You should see the MySQL command prompt, indicating that MySQL is running correctly.

Step 7: Basic MySQL Configuration

Once logged in, you can perform basic MySQL configurations such as creating databases and users.

  1. Create a new database:

    CREATE DATABASE mydatabase;

  2. Create a new user and grant privileges:

    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES;

  3. Exit the MySQL shell:

    EXIT;

Conclusion

Installing MySQL on RHEL 9 / Rocky Linux 9 involves several steps to ensure a secure and optimized setup. By following this guide, you have installed MySQL, secured your installation, and performed basic configurations to get started with using MySQL on your system.

Compelling Summary: Master MySQL installation on RHEL 9 / Rocky Linux 9 with this comprehensive guide, ensuring a robust and secure database setup.

References

By following these steps, you will have a fully functional MySQL database server ready to handle your data needs efficiently and securely on RHEL 9 or Rocky Linux 9.