Introduction:
MySQL is one of the most popular and widely used open-source relational database management systems. It provides a robust and scalable platform for storing and managing data. In this article, we will guide you through the process of installing MySQL on Rocky Linux 9, enabling you to set up a powerful database system for your applications.
Step 1: Update System Packages:
Before installing any software, it is important to update the system packages to their latest versions. Open a terminal on your Rocky Linux 9 server and execute the following command:
sudo dnf update
This command will update the package repositories and ensure that your server has the most recent package information.
Step 2: Install MySQL:
Rocky Linux 9 includes the MySQL package in its default repositories, making the installation process simple. Run the following command to install MySQL:
sudo dnf install mysql-server
This command will install the MySQL server and its dependencies.
Step 3: Start and Enable MySQL:
Once the installation is complete, start the MySQL service using the following command:
sudo systemctl start mysqld
To ensure that MySQL starts automatically on system boot, enable the service by running:
sudo systemctl enable mysqld
Step 4: Secure MySQL Installation:
To secure your MySQL installation, run the following command:
sudo mysql_secure_installation
This command will prompt you to set the root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables. Follow the on-screen prompts and answer “Y” or “N” to the provided questions based on your requirements.
Step 5: Verify MySQL Installation:
To verify that MySQL is installed and running correctly, you can check its status using the following command:
sudo systemctl status mysqld
If MySQL is active and running, you should see a “active (running)” status.
Step 6: Access MySQL:
To access the MySQL command-line interface, use the following command:
sudo mysql -u root -p
Enter the root password you set during the secure installation process. You should now be logged in to the MySQL shell.
Step 7: Optional: Configure Firewall:
If the firewall is enabled on your Rocky Linux 9 server, you need to allow access to the MySQL port (3306) to allow remote connections. Run the following command to add the necessary firewall rule:
sudo firewall-cmd --add-service=mysql --permanent sudo firewall-cmd --reload
Conclusion:
Congratulations! You have successfully installed MySQL on Rocky Linux 9. By following the step-by-step guide, you now have a powerful and reliable database management system ready to store and manage your data. Remember to follow best practices for database administration and security, such as creating separate user accounts, managing database permissions, and regularly backing up your data. MySQL offers a wide range of features and functionalities that can support your applications and help you build efficient and scalable database solutions.