How To Install MySQL on AlmaLinux 9

In this guide on the Orcacore website, 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 on the Initial Server Setup with AlmaLinux 9.

1. Install MySQL Community Edition on 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:

Default Root Password of MySQL

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:

Change the Default Root Password of MySQL

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 Install MySQL LTS on AlmaLinux 9 and change its default root password. Installing MySQL LTS 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.

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

Share your love

Stay informed and not overwhelmed, subscribe now!