How To Install MySQL on AlmaLinux 9

In this guide, we want to teach you How To Install MySQL on AlmaLinux 9.

MySQL is one of the most recognizable technologies in the modern big data ecosystem. Often called the most popular database and currently enjoying widespread, effective use regardless of industry, it’s clear that anyone involved with enterprise data or general IT should at least aim for a basic familiarity with MySQL.

With MySQL, even those new to relational systems can immediately build fast, powerful, and secure data storage systems. MySQL’s programmatic syntax and interfaces are also perfect gateways into the wide world of other popular query languages and structured data stores.

Steps To Install MySQL on AlmaLinux 9

In this guide, you learn to install MySQL in the latest release on AlmaLinux 9.

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with AlmaLinux 9.

Install MySQL Community Edition on AlmaLinux 9

To install the latest release of MySQL on your server is to use MySQL RPM.

First, you need to import the official MySQL Community RPM from its official downloads page with the command below:

sudo rpm -ivh

Then, verify that the repository is added successfully to your server with the following command:

dnf repolist all | grep mysql | grep enabled
mysql-connectors-community            MySQL Connectors Community        enabled
mysql-tools-community                 MySQL Tools Community             enabled
mysql80-community                     MySQL 8.0 Community Server        enabled

Now use the following command to enable the MySQL community edition on AlmaLinux 9:

sudo dnf install mysql-community-server -y

Verify your MySQL installation by checking its version:

mysql --version
mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

Enable your MySQL service on AlmaLinux 9:

sudo systemctl enable mysqld --now

This will activate MySQL in your current session, and on future systems, restarts automatically.

Also, you can check your MySQL service is active and running on your server with the command below:

sudo systemctl status mysqld

In your output you will see:

● mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pr>
     Active: active (running) since Tue 2022-10-11 05:58:06 EDT; 20s ago
       Docs: man:mysqld(8)
    Process: 16920 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, statu>
   Main PID: 16998 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 23609)
     Memory: 457.1M
        CPU: 5.722s
     CGroup: /system.slice/mysqld.service
             └─16998 /usr/sbin/mysqld

Now that you have MySQL service installed on your AlmaLinux 9, you can secure it by running the security script.

Change the Default Root Password of MySQL

At this point, you can secure your MySQL service by running a single security script.

By default, MySQL generates a default root password for you when starting the service for the first time. The password is stored in the MySQL log file ‘/var/log/mysqld.log’.

To display the default root password, you can use the following command:

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

You will get similar output like this:

A temporary password is generated for sam@localhost: Dzj*F=?4K.l#

Then, run the command below to secure your MySQL service on AlmaLinux 9 and change your default root password:

sudo mysql_secure_installation

You will be asked to enter the root password. You should enter the default MySQL root password.

Then, you will get the following message:

The existing password for the user account root has expired. Please set a new password. 
New password: <---- SET NEW PASSWORD 
Re-enter new password: <---- RE-ENTER NEW PASSWORD

Here you need to enter your new password and press enter.

After that, you will be asked to change the root password, SKIP IF YOU ALREADY JUST SET.

From here press Y to continue.

Now you can log in to your MySQL shell with the command below and the new password you have generated:

sudo mysql -u root -p

You will see your MySQL console:

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


If you no longer wish to use the MySQL database and want to remove it in full, execute the following command:

sudo dnf remove mysqld


At this point, you have learned to Install MySQL LTS on AlmaLinux 9 and change its default root password.

Hope you enjoy it.

You may be interested in this article on the OrcaCore website:

Install and Configure phpMyAdmin on AlmaLinux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!