Install MySQL on Rocky Linux 9 | Efficient Steps

In this guide on the Orcacore website, we want to teach you How To Install MysQL on Rocky Linux 9. MySQL is an open-source relational database management system (RDBMS) with a client-server model. RDBMS is a software or service used to create and manage databases based on a relational model. 

Steps To Install and Access MySQL on Rocky Linux 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 Initial Server Setup with Rocky Linux 9.

1. Install MySQL on Rocky Linux 9

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

sudo dnf update -y

Then, use the following command to install the mysql-server package and a number of its dependencies:

sudo dnf install mysql-server -y

When your installation is completed, you need to start and enable your service.

Start and Enable MySQL Service

At this point, use the following commands to start and enable MySQL to start on boot:

# sudo systemctl start mysqld.service
# sudo systemctl enable mysqld

Also, you can check your MySQL service is active and running on your Rocky Linux 9 with the command below:

sudo systemctl status mysqld

In your output you will see:

Check MySQL status

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

2. Change MySQL Default Root Password

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 similar output like this:

Display default MySQL root password

Then, run the command below to secure your MySQL service on Rocky Linux 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.

Access MySQL Shell

Now you can log in to your MySQL shell on Rocky Linux 9 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.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>

For more information, you can visit the MySQL Documentation page.

3. Uninstall MySQL From Rocky Linux

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 on Rocky Linux 9. Using MySQL on Rocky Linux 9 provides a stable, secure, and high-performance database solution. It ensures compatibility with modern applications, improved scalability, and efficient data management for enterprise and web applications.

Hope you enjoy it. You may also like these articles:

How To Install MySQL on AlmaLinux 9

How To Install MySQL 8.0 on Debian 11

Turn Off MySQL Strict Mode on Linux

Duplicate a MySQL Database with a Different Name

Reset MySQL Root Password on Rocky Linux

Share your love

Stay informed and not overwhelmed, subscribe now!