How To Install MySQL on AlmaLinux 8

In this article, we want to teach you How To Install MySQL on AlmaLinux 8.

MySQL is a relational database management system based on SQL (Structured Query Language). It is one of the most widely used database software for several well-known applications that utilize it. MySQL is used for data warehousing, e-commerce, and logging applications, but its most used feature is a web database storage and management.

AlmaLinux comes with MySQL in its AppStream, but it is not in the latest release.

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

How To Install MySQL on AlmaLinux 8

Before you start to install MySQL on your server, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with AlmaLinux 8.

Now follow the steps below to complete this guide.

We will show you to install MySQL from AppStream and its community edition.

Install MySQL from AppStream on ALmaLinux 8

First, you need to update your local package index with the command below:

sudo dnf update -y

Then, check the MySQL versions that are available in the AlmaLinux repository with the command below:

sudo dnf module list mysql

In your output you will see:

Output
Last metadata expiration check: 0:18:31 ago on Thu 24 Feb 2022 02:33:13 AM EST.
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
mysql 8.0 [d] client, server [d] MySQL Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

As you can see the latest available version of MySQL is 8.0. You can use the command below to enable MySQL 8.0 module on AlmaLinux 8:

sudo dnf module enable mysql:8.0 -y

Next, use the following command to install it:

sudo dnf install mysql

Verify your installation by checking its version:

mysql --version
Output
mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)

Now use the command below to enable MySQL on AlmaLinux 8:

sudo systemctl enable mysqld --now

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

Install MySQL Community Edition on AlmaLinux 8

The other way to install the latest release of MySQL on your server is using the 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-el8-3.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 disable the App Stream version and enable the community edition:

sudo dnf install --disablerepo=appstream mysql-community-server

Verify your MySQL installation by checking its version:

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

Enable your MySQL service on AlmaLinux 8:

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:

systemctl status mysqld

In your output you will see:

Output
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset>
Active: active (running) since Thu 2022-02-24 03:10:42 EST; 4min 3s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 91202 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/>
Main PID: 91291 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 11409)
Memory: 484.8M
CGroup: /system.slice/mysqld.service
└─91291 /usr/sbin/mysqld

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

Secure MySQL with Security Script

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 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:

Output
A temporary password is generated for [email protected]: o;j1.(DGPsDK

Then, run the command below to secure your MySQL service on AlmaLinux 8 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 15
Server version: 8.0.28 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 learn to Install MySQL on ALmaLinux 8.

Hope you enjoy it.

May this article about How To Install MySQL on Centos 7 be useful for you.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular