How to Install MySQL 8.0 on Rocky Linux 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.

Rocky Linux comes with MySQL in its repository. 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 Rocky Linux 8.

Prerequisites

  • Recommended OS: Rocky Linux 8.+.
  • User account: A user account with sudo or root access.

Update Operating System

Update your Rocky Linux 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@rockylinux ~]$ sudo whoami
root

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

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 Rocky Linux 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 Rocky Linux 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

Proceed with the installation using the following terminal command.

sudo dnf install mysql

Example output:

How to Install MySQL 8.0 on Rocky Linux 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 Community RPM.

sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.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 Rocky Linux 8

Next, install MySQL 8.0 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 Rocky Linux 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 Rocky Linux 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)

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 Rocky Linux 8

To stop the MySQL service:

sudo systemctl stop mysql

To start the MySQL service:

sudo systemctl start mysql

To disable the MySQL service on system boot:

sudo systemctl disable mysql

To enable the MySQL service on system boot:

sudo systemctl enable mysql

To restart the MySQL service:

sudo systemctl restart mysql

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

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:

How to Install MySQL 8.0 on Rocky Linux 8

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 Rocky Linux 8

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 Rocky Linux 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 Rocky Linux 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!