How To Install MySQL on AlmaLinux 9 | Easy Setup – OrcaCore
In this guide on the OrcaCore website, we aim to teach you How To Install MySQL on AlmaLinux 9. MySQL stands as one of the most recognizable technologies in the modern big data ecosystem. Often lauded as 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.
In this guide, you learn to How To Install MySQL on AlmaLinux 9 in the latest release. 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 on the Initial Server Setup with AlmaLinux 9.
To install the latest release of MySQL on your server, 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 https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
Then, verify that the repository is added successfully to your server with the following command:
dnf repolist all | grep mysql | grep enabled
**Output**
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
**Output**
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, it restarts automatically.
Also, you can check whether your MySQL service is active and running on your server with the command below:
sudo systemctl status mysqld
In your output, you will see:
**Output**
● 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)
http://dev.mysql.com/doc/refman/en/using-systemd.html
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.
2. 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 output similar to this:

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:
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
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
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
Conclusion
At this point, you have learned to How To Install MySQL on AlmaLinux 9 and change its default root password. Installing MySQL on AlmaLinux 9 ensures a stable, secure, and high-performance database system. It provides long-term support, making it ideal for production environments and enterprise applications. This is the most effective way to How To Install MySQL on AlmaLinux 9.
Hope you enjoy it. You may also like the following articles:
Install and Configure phpMyAdmin on AlmaLinux 9
Installing FastAPI with MongoDB on Ubuntu 24.04
Install Podman on Ubuntu 24.04
Alternative Installation Methods for MySQL on AlmaLinux 9
While the RPM method detailed above is a common and generally reliable way to install MySQL, there are alternative approaches that may be preferable in certain situations. Here are two such alternatives: using a containerization platform like Docker and leveraging the AlmaLinux’s built-in module system.
1. Installing MySQL with Docker
Docker provides a way to package applications and their dependencies into isolated containers. This can be particularly useful for ensuring consistency across different environments and simplifying deployment.
Explanation:
Using Docker to install MySQL abstracts away much of the operating system-specific configuration. The Docker image contains everything MySQL needs to run, including the necessary libraries and dependencies. This eliminates potential conflicts with other software installed on the AlmaLinux 9 system. It makes How To Install MySQL on AlmaLinux 9 easier.
Steps:
-
Install Docker: If Docker isn’t already installed, you’ll need to install it first. Follow the official Docker documentation for installing Docker on CentOS (which is very similar to AlmaLinux):
https://docs.docker.com/engine/install/centos/
-
Pull the MySQL Docker Image: Obtain the official MySQL image from Docker Hub:
sudo docker pull mysql:latest
-
Run the MySQL Container: Create and run the MySQL container, setting the root password and exposing the necessary port:
sudo docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=your_root_password -p 3306:3306 -d mysql:latest
--name mysql-container
: Assigns a name to the container.-e MYSQL_ROOT_PASSWORD=your_root_password
: Sets the MySQL root password. Replaceyour_root_password
with a strong password.-p 3306:3306
: Maps port 3306 on the host machine to port 3306 in the container.-d
: Runs the container in detached mode (in the background).mysql:latest
: Specifies the Docker image to use.
-
Connect to MySQL: You can now connect to the MySQL server running in the Docker container using a MySQL client.
mysql -h 127.0.0.1 -P 3306 -u root -p
Enter the root password you set earlier.
Code Example (docker-compose.yml):
For more complex setups, Docker Compose can be used to define and manage multi-container applications. Here’s a docker-compose.yml
file for MySQL:
version: "3.8"
services:
db:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: your_root_password
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
To start the MySQL container using Docker Compose:
docker-compose up -d
This creates a persistent volume for the MySQL data and simplifies the container management process.
2. Installing MySQL with AlmaLinux Modules
AlmaLinux provides a module system that allows users to choose different versions of software packages. This can be useful if you need a specific version of MySQL for compatibility reasons.
Explanation:
AlmaLinux modules offer a streamlined way to manage different software versions. By enabling a specific MySQL module, you ensure that all the necessary dependencies and configurations are set up correctly for that version. This simplifies the installation process and reduces the risk of conflicts. This makes How To Install MySQL on AlmaLinux 9 a lot easier.
Steps:
-
List Available MySQL Modules: Use the
dnf module list
command to see the available MySQL modules:sudo dnf module list mysql
This will show the available MySQL versions and their streams.
-
Enable the Desired Module: Enable the desired MySQL module stream. For example, to enable the
mysql:8.0
stream:sudo dnf module enable mysql:8.0
-
Install MySQL: Install the MySQL server package:
sudo dnf install mysql-server
-
Start and Enable MySQL: Start the MySQL service and enable it to start on boot:
sudo systemctl start mysqld sudo systemctl enable mysqld
-
Secure the Installation: Run the
mysql_secure_installation
script to secure your MySQL installation:sudo mysql_secure_installation
Code Example (Module Configuration):
While you don’t directly write code for module installation, understanding the module configuration is helpful. Module configurations are typically stored in /etc/dnf/modules.d/
. A module configuration file for MySQL might look like this (simplified):
[mysql]
name=mysql
stream=8.0
profiles=server
state=enabled
This file specifies the name of the module, the enabled stream, and the profile to install (in this case, the server profile).
Both of these alternative methods offer advantages over the standard RPM installation, depending on your specific needs and environment. Docker provides isolation and portability, while AlmaLinux modules offer version management and simplified configuration.