How to Install MySQL 8.0 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. However, as many know, it is not the latest release. In the following tutorial, you will learn how to install MySQL 8.0 using the AppStream or the latest Community version RPM from MySQL repositories on AlmaLinux 8.

Prerequisites

  • Recommended OS: AlmaLinux 8.
  • User account: A user account with sudo privilages or root access (su command).

Updating Operating System

Update your AlmaLinux operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@localhost ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on How to Add a User to Sudoers on AlmaLinux.

To use the root account, use the following command with the root password to log in.

su

Option 1. Install MySQL 8.0 with AppStream

By default, MySQL 8.0 is available as the default choice in AlmaLinux and is entirely up to date. First, verify if any other versions are available with the following command.

sudo dnf module list mysql

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

Currently, at the time of this tutorial, only MySQL 8.0 is available and is the default shown with the [d] flag.

By some chance, you have not enabled MySQL 8, use the following command.

sudo dnf module enable mysql:8.0 -y

Proceed with the installation using the following terminal command.

sudo dnf install mysql

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

Type Y, then press the ENTER KEY to proceed with the installation.

Re-run the installation command to start over.

Once the installation has been completed, verify the installation using the –version command.

mysql --version

Example output:

mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)

Next, enable MySQL 8 using the following command.

sudo systemctl enable mysqld --now

The above command will activate MySQL in your current session, and on future systems, restarts automatically.

Option 2. Install MySQL 8.0 Community Edition (Latest)

For users that require the latest MySQL 8.0 or, for that matter, any alternative version, using the following steps below will achieve this.

Note, at the time of this tutorial, the difference between AppStream and the latest from MySQL RPM is minor. For the majority, the AppStream will be more ideal.

First, use the following command to import the official MySQL 8.0 Community RPM.

sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm

Next, verify the repository was added successfully by printing it out from the dnf repolist.

dnf repolist all | grep mysql | grep enabled

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

Next, install MySQL 8 Community Server. The following command will disable the App Stream version and enable the community edition.

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

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

Type Y, then press the ENTER KEY to proceed with the installation.

Note, you will be asked to import GPG keys, Type Y, to complete the installation.

Example:

How to Install MySQL 8.0 on AlmaLinux 8

Next, confirm the version build, which will also verify the installation’s success.

mysql --version

Example output:

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

Next, enable MySQL 8 using the following command.

sudo systemctl enable mysqld --now

The above command will activate MySQL in your current session, and on future systems, restarts automatically.

Check MySQL 8 Server Status

The installer will automatically start your MySQL service by default and configure itself to auto-start on system boot. To verify your MySQL service is operational after the installation, type the following systemctl command:

systemctl status mysql

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

To stop the MySQL service:

sudo systemctl stop mysqld

To start the MySQL service:

sudo systemctl start mysqld

To disable the MySQL service on system boot:

sudo systemctl disable mysqld

To enable the MySQL service on system boot:

sudo systemctl enable mysqld

To restart the MySQL service:

sudo systemctl restart mysqld

Secure MySQL 8 with Security Script

When installing MySQL fresh, default settings are considered weak by most standards and cause concern for potentially allowing intrusion or exploiting hackers. A solution is to run the installation security script that comes with the MySQL installation.

First, use the following command to launch the (mysql_secure_installation):

sudo mysql_secure_installation

By default, the root password should be blank, if by some reason the password has been set use the following command to generate a temporary password to login to the MySQL Security script and during the set up you will set a new password.

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

You will be prompted to enter your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this is to set password complexity checks; for most, the default is fine.

Next, follow below:

  • Setting the password for root accounts.
  • Setting the password strength for accounts.
  • Removing root accounts that are accessible from outside the local host.
  • Removing anonymous-user accounts.
  • Removing the test database, which by default can be accessed by anonymous users.

Note, you use (Y) to remove everything. Also, if you like, you can reset your root password by creating a new one; you can skip this if you want, as you already set it during the initial installation with the pop-up windows.

Example:

[joshua@almalinux ~]$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

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

Re-enter new password: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY (SKIP IF YOU ALREADY JUST SET)

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.

All done! 

Login to MySQL 8 instance

Now that you have completed the post-installation installation security script, login into your MySQL database can be done using the following:

sudo mysql -u root -p

You will be prompted to enter the root password that you set in either the installation setup or post-installation security script. Once inside the MySQL service instance, you can execute the following command as a test to see it in operation.

Type the following SHOW DATABASE command:

SHOW DATABASES;

For those new to MySQL, all commands must end with “;

Example:

How to Install MySQL 8.0 on AlmaLinux 8

To create a database, use the following command.

CREATE DATABASE MYDATA;

To delete (drop) a database, use the following command.

DROP DATABASE MYDATA;

To exit the terminal, type the following exit command:

EXIT;

How to Remove (Uninstall) MySQL 8

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

sudo dnf remove mysql

Example output:

How to Install MySQL 8.0 on AlmaLinux 8

Type Y, then press ENTER KEY to proceed with the uninstallation.

For users that installed the MySQL 8 community edition, use the following command.

sudo dnf remove mysql-community-server

Comments and Conclusion

In the tutorial, you have learned how to install the latest MySQL 8 on AlmaLinux 8. In addition, along with options to optimize for specific workloads on specific hardware by mapping user threads to CPUs, to name a few of the new features.

Overall, MySQL 8 has better performance for reading/write workloads, IO-bound workloads, and high contention workloads. Users on older versions of MySQL should consider upgrading, as the performance gains are worth it.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!