Installing MySQL

Step-by-Step Guide to Install MySQL 8 on CentOS Stream 9

MySQL is a powerful, open-source relational database management system, renowned for its reliability and scalability. CentOS Stream 9, a continuously released Linux distribution, offers a flexible platform for hosting a MySQL database. This step-by-step guide will walk you through the process of installing MySQL 8 on CentOS Stream 9 and how to create a database and tables post-installation. Combining MySQL with CentOS Stream 9 enables you to create a reliable environment for database-driven applications and web services.

Prerequisites

Before starting the installation, ensure you have the following prepared:

  • Access to CentOS Stream 9 Server: You should have SSH access to your CentOS Stream 9 server. If not, consider setting up a virtual machine or using a cloud server.

  • Root or Sudo Privileges: You need root or sudo privileges on the server to install and configure MySQL.

  • System Update: Ensure your CentOS Stream 9 system is up to date by running the following command:

    sudo dnf update
    
  1. Adding the MySQL Yum Repository MySQL offers official Yum repositories that simplify the installation process. Follow these steps to add the repository:
  • Download the MySQL Yum repository configuration package:

    sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
    
  • After downloading the RPM package, enable the MySQL repository:

    sudo dnf config-manager --enable mysql80-community
    
  1. Installing MySQL Server With the repository added, you can proceed to install MySQL:
  • Install MySQL Server and client using the following command:

    sudo dnf install mysql-server
    
  • Start the MySQL service and enable it to launch on system startup:

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
  • Retrieve the initial MySQL root password using this command:

    sudo grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}'
    

    Note this password; you will need it for MySQL login in the next step.

  • Secure your MySQL installation by running the MySQL secure installation script:

    sudo mysql_secure_installation
    

    Follow the prompts to configure security settings for your MySQL installation, including changing the root password if desired.

  1. Accessing MySQL Access the MySQL interface using this command:
mysql -u root -p

You will be prompted to enter the root password obtained in the previous step.

  1. Creating a Database and Tables
mysql> CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> CREATE USER 'wp_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> GRANT ALL ON wordpress_db.* TO 'wp_user'@'%';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;