How to Install MySQL 8.0 on Rocky Linux 9

Advertisement

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. MySQL is used for data warehousing, e-commerce, and logging applications, but web database storage and management is the most commonly used feature. MySQL has been in production use for over 20 years and is considered one of the most secure and reliable database systems. Despite this, it has several drawbacks that should be considered before using it for any mission-critical applications. One such drawback is that it does not support transactions across multiple tables, which can lead to data inconsistency in the event of a failure. Additionally, MySQL does not support some of the more advanced features in other database systems, such as stored procedures and triggers. MySQL is an excellent choice for many applications, but it must be aware of its limitations before using it in a production environment.

In the latest release of MySQL 8.0, the database management system brings new features and security updates. This new release of MySQL adds support for joins with larger data sets, better performance when importing large files, and various improvements to InnoDB, SQL mode, named ‘strict sql_mode,’ which will make MySQL more compliant with the SQL standard. In addition, there are performance enhancements for DML statements and replication and several new security features. With these improvements, MySQL 8.0 provides a more robust and secure platform for managing data.

In the following tutorial, you will learn how to install MySQL 8.0 on Rocky Linux 9 using the command line terminal with instructions on how to secure the MySQL service, update, and, if necessary, remove.

Update Rocky Linux

Before you continue, your system is advised to ensure all existing packages are up to date to avoid system conflicts during the installation and good system maintenance.

sudo dnf upgrade --refresh -y

Next, you have two options, install the standard MySQL from the appstream or install the latest stable MySQL 8.0 version dubbed the community version.

Advertisement

Install MySQL 8.0 – Appstream Method

MySQL 8.0 is available as the default choice in Rocky Linux 9. Run the following command to install.

sudo dnf install mysql mysql-server -y

While you can include quite a few options, another popular option is installing the developer kit and standard MySQL installation.

Advertisement

Note this is only for developers, not CMS/Webserver users.

sudo dnf install mysql mysql-server mysql-devel -y

When the installation is complete, verify the installation using the –version command.

mysql --version

Then activate MySQL 8 using the following command.

sudo systemctl enable mysqld --now

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

Advertisement

Install MySQL 8.0 – MySQL Community Edition (Latest)

For those users who need the latest version of MySQL 8.0 or, for that matter, any other version, the following steps below will accomplish this goal.

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

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

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

Example output:

Advertisement
How to Install MySQL 8.0 on Rocky Linux 9

As above, you are now installing directly from the MySQL RPM repository.

Then confirm the build of the version, which will also verify the success of the installation.

Advertisement

mysql --version

Example output:

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

Then activate MySQL 8.0 using the following command.

sudo systemctl enable mysqld --now

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

Check the Status of the MySQL 8.0

The installer will automatically start your default MySQL service and configure itself to start automatically on system startup.

Verify that your MySQL service is operational after installation; type the following systemctl status command.

systemctl status mysqld

Example output:

Advertisement
Advertisement

How to Install MySQL 8.0 on Rocky Linux 9

For new installations, everything should be status ok. Proceed on to securing your MySQL instance.

Below are some of the most common system commands you will require to manage your MySQL systemd service.

Stop the MySQL service:

sudo systemctl stop mysqld

Start the MySQL service:

sudo systemctl start mysqld

Disable the MySQL service at system startup:

sudo systemctl disable mysqld

Activate the MySQL service at system startup:

Advertisement

sudo systemctl enable mysqld

Restart the MySQL service:

sudo systemctl restart mysqld

How to Secure MySQL 8.0

When installing MySQL, the new defaults are considered weak by most standards and raise concerns about the potential of allowing intrusion or exploitation by hackers. One solution is to run the installation security script with the MySQL installation.

Advertisement

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

sudo mysql_secure_installation

Skip the temporary password command; read this quick tip if you have an issue.

For users that receive the following error that installed the MySQL 8.0 Community version.

Error: Access denied for user 'root'@'localhost' (using password: NO)

By default, the root password should be blank. If the password has been set for some reason, use the following command to generate a temporary password to log into the MySQL Security script. During configuration, you will set a new password.

Advertisement

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

Example output:

2022-08-13T06:46:17.111312Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wzP8ya8ZPn?g

As above, you now have your temporary password; you will be prompted to change this on login with your MySQL root account as the command suggests; it is designed to be temporary.

Next, you will be prompted for your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this involves defining password complexity checks; for the most part, the default is correct.

Then follow below:

Advertisement
  • Setting the password for root accounts.
  • Setting the password for the accounts.
  • Removal of root accounts accessible from outside the localhost.
  • Removal of anonymous user accounts.
  • Removal of the test database, accessible by default to anonymous users.

Be careful; you use (Y) to delete everything. In addition, if you wish, you can reset your root password by creating a new one; you can ignore it if you want, as you already set it during the initial installation with the pop-ups.

Example:

Advertisement

[joshua@rockylinux-9 ~]$ 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! 

How to Update/Upgrade MySQL 8.0

Given both versions were installed using the command terminal with DNF repositories, use a typical update command as below to check for updates.

sudo dnf update --refresh

How to Remove (Uninstall) MySQL

Users that no longer require MySQL use the following command to remove all traces of the database software.

sudo dnf autoremove mysql mysql-server -y

Users wishing to remove the Community Edition to scale back too, for example, the appstream version or delete the software, are ideal for removing all the RPM repositories.

sudo rm /etc/yum.repos.d/mysql-community*

Comments and conclusion

If you are looking for a powerful and versatile database management system, MySQL is an excellent option to consider. It has a large user base and community support, making it easy to find help when needed. Additionally, its open source license means that it is free to use. While there are some potential drawbacks to using MySQL (such as the need for additional software for backup and security), overall, it is a perfect choice for managing your data.

Share on: