Search

Step-by-Step Guide: How to Install MySQL Rocky Linux 9

Welcome to our step-by-step guide on installing MySQL on Rocky Linux 9. If you're looking for a reliable and powerful open-source Relational Database Management System (RDBMS), MySQL is the perfect choice. With its use of Structured Query Language (SQL), MySQL provides a robust platform for storing and managing your data.

To get started, follow our simple instructions to install MySQL on your Rocky Linux 9 system. In this installation guide, we'll walk you through the process, ensuring that you have a smooth and hassle-free experience.

By the end of this guide, you'll have a fully functional MySQL server up and running on your Rocky Linux 9 system. So let's dive in and discover the step-by-step process of installing MySQL.

Enabling the MySQL 8 Module and Installing MySQL Server

Now that you have a basic understanding of MySQL and have installed Rocky Linux 9, it's time to enable the MySQL 8 module and install the MySQL server. This will allow you to start working with databases and managing data efficiently.

To enable the MySQL 8 module on Rocky Linux 9, open your terminal and enter the following command:

sudo dnf module enable mysql -y

This command will enable the MySQL 8 module, which is required to install the MySQL server. Once the module is enabled, you can proceed with the installation.

To install the MySQL server, enter the following command in your terminal:

sudo dnf install @mysql -y

This command will download and install the MySQL server along with all the necessary packages. Depending on your internet connection speed, this process may take a few minutes.

Once the installation is complete, you will have a fully functional MySQL server on Rocky Linux 9, ready to create and manage databases. In the next section, we will cover how to start and secure your MySQL installation.

Starting and Securing the MySQL Installation

Now that you have successfully installed MySQL on Rocky Linux 9, it's time to start the MySQL service and secure your installation. To start the MySQL service, simply run the following command:

sudo systemctl start mysqld

Once the service is started, you can proceed to secure your MySQL installation to protect it from unauthorized access. Run the following command to initiate the MySQL Secure Installation wizard:

sudo mysql_secure_installation

This wizard will guide you through a series of prompts to set a root password, remove anonymous users, disable remote root login, remove the test database, and reload the privileges. It is recommended to follow all the steps for enhanced security.

Securing your MySQL installation

During the secure installation process, you will be prompted to:

  1. Set a root password: Choose a strong password for the root user, which will be the main administrator account for your MySQL server.
  2. Remove anonymous users: By removing the anonymous users, you prevent anyone from accessing your MySQL server without proper authentication.
  3. Disable remote root login: Disabling remote root login ensures that the root account can only be accessed from the local machine, further protecting your MySQL server.
  4. Remove the test database: The test database is created by default during the installation process. It is recommended to remove it to prevent any potential security risks.
  5. Reload privileges: Reloading the privileges will enforce the changes made during the secure installation process.

Once you have completed these steps, your MySQL installation on Rocky Linux 9 will be both started and secured, ensuring the safety of your data and the integrity of your server.

Managing the MySQL Service

Once you have successfully installed MySQL on Rocky Linux 9, you can manage the MySQL service using a few simple commands. These commands allow you to start, stop, restart, and check the status of the MySQL service on your system. Here are the essential commands you need to know:

Start MySQL: To start the MySQL service, use the command sudo systemctl start mysqld.

Stop MySQL: If you need to stop the MySQL service, you can use the command sudo systemctl stop mysqld.

Restart MySQL: To restart the MySQL service, simply run the command sudo systemctl restart mysqld. This will stop and then start the service again.

Check MySQL status: To check the status of the MySQL service, use the command sudo systemctl status mysqld. This will provide you with information such as whether the service is running or not.

By using these commands, you can easily manage the MySQL service on your Rocky Linux 9 system. Whether you need to start, stop, or check the status of the service, these commands give you the flexibility to control the MySQL service according to your needs.

Creating a Dedicated MySQL User and Testing the Connection

Creating a dedicated MySQL user is an important step in securing your MySQL installation on Rocky Linux 9. To do this, run the following command:
 

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';

Replace 'myuser' and 'password' with your desired username and password. This dedicated MySQL user will have all privileges on all databases. This not only enhances security but also allows for more granular control over user access and permissions.

Once the dedicated user is created, it's important to test the MySQL connection using this user. You can do this by running the following command:
 

mysql -u myuser -p

This command prompts you to enter the password for the 'myuser' account. If the connection is successful, you will be logged into the MySQL server. This confirms that the dedicated user has proper access and can interact with the databases. You are now ready to start using MySQL on Rocky Linux 9.

Conclusion

In this comprehensive guide, you have learned how to install MySQL on Rocky Linux 9. By following the step-by-step instructions, you can now set up a fully functional MySQL server on your system.

Starting with enabling the MySQL 8 module and installing the MySQL server, you have taken the first steps towards creating a powerful database management system. Additionally, securing the MySQL installation ensures the safety of your data and protects against potential vulnerabilities.

Managing the MySQL service allows you to control its functionality, whether it's starting, stopping, restarting, or checking its status. These commands provide you with the necessary tools to ensure that your MySQL server is running smoothly.

Finally, by creating a dedicated MySQL user and testing the connection, you can ensure the security and functionality of your database. With these steps completed, you can confidently store and manage your data using MySQL on your Rocky Linux 9 system.

By following this guide, you have acquired the knowledge and skills to successfully install and configure MySQL on Rocky Linux 9. MySQL is a powerful tool that can enhance your data management capabilities, making it an invaluable addition to your system.

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...