How To Install MysQL on Rocky Linux 9

In this guide, 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 MySQL on Rocky Linux 9

To complete this guide, you must log in t 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.

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:

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

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

Run MySQL Security Script on Rocky Linux 9

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

Output
A temporary password is generated: o;j1.(DGPsDK

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.

Uninstall 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 have learned to Install MySQL on Rocky Linux 9.

Hope you enjoy it.

You may be like these articles:

How To Install MySQL on AlmaLinux 9

How To Install MySQL 8.0 on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!