Search

Step-by-Step Guide: How to Install MySQL on AlmaLinux 9

Welcome to our step-by-step guide on how to install MySQL on AlmaLinux 9. MySQL is a popular open-source Relational Database Management System that is widely used for managing data using Structured Query Language (SQL). By following this guide, you will be able to set up a fully functional MySQL database server on your AlmaLinux 9 server.

Whether you are new to MySQL or have previous experience, our easy-to-follow instructions will help you complete the installation process smoothly. Let's get started and learn how to install MySQL on AlmaLinux 9 in just a few simple steps.

Throughout this guide, we will cover the prerequisites you need, provide detailed instructions on how to install MySQL using DNF package manager, explain how to start and check the MySQL service, and guide you on securing your MySQL installation to protect it from unauthorized access.

Once you have completed the installation, we will also show you how to connect to the MySQL server and verify that it is working correctly. Additionally, you will learn how to uninstall MySQL from your AlmaLinux 9 server if needed.

By the end of this guide, you will have a fully functional MySQL installation on your AlmaLinux 9 server, ready to use for your database management needs. So let's dive in and begin the installation process!

Prerequisites

Before you begin the installation process, there are a few prerequisites you need to fulfill to ensure a smooth installation of MySQL on your AlmaLinux 9 server.

Firstly, make sure you have a Linux VPS running AlmaLinux 9. This will serve as the foundation for your MySQL installation.

Secondly, you will need root or superuser access to the server. This level of access allows you to run the necessary commands and install the required software for MySQL.

By having these prerequisites in place, you can proceed with confidence, knowing that you have everything you need for a successful installation process.

Install MySQL on AlmaLinux 9 using DNF

Installing MySQL on AlmaLinux 9 is a breeze when using the DNF package manager. Follow these steps to get your MySQL server up and running:

  1. Open a terminal on your AlmaLinux 9 server.
  2. Run the following command to install MySQL and its dependencies:

sudo dnf install mysql-server

This command will download and install the necessary packages for MySQL.

Once the installation is complete, you can start the MySQL service by running the following command:

sudo systemctl start mysqld

You can also check the status of the service to ensure it is running correctly:

sudo systemctl status mysqld

That's it! You now have MySQL installed on your AlmaLinux 9 server using DNF.

Additional Tips:

  • If you want MySQL to start automatically when your server boots up, you can enable it by running:

sudo systemctl enable mysqld

  • To configure the MySQL server, you can edit the /etc/my.cnf file.

With MySQL successfully installed, you're one step closer to leveraging the power of a reliable and efficient relational database management system on your AlmaLinux 9 server.

Start and Check the MySQL Service

After the installation is complete, you need to start the MySQL service and check its status to ensure that it is running correctly. To start the service, run the following commands:

sudo systemctl start mysqld

sudo systemctl status mysqld

The first command starts the MySQL service, and the second command checks the status of the service. If the service is running properly, you will see a message indicating that the service is active and running. This confirms that the installation was successful.

Additionally, you can enable the MySQL service to start automatically on system boot by running the following command:

sudo systemctl enable mysqld

This command ensures that the MySQL service will start automatically each time you reboot your AlmaLinux 9 server.

Secure Your MySQL Installation

Securing your MySQL installation is essential to protect your data from unauthorized access. Luckily, MySQL provides a handy script called mysql_secure_installation that can help you with this task. To start the script, open a terminal and enter the following command:

mysql_secure_installation

This script will guide you through several security-related options. Here are the steps you can expect:

  1. You will be prompted to enter the password for the MySQL root user. Provide the password you set during the installation process.
  2. The script will then ask if you want to remove anonymous users. It's recommended to answer 'Y' to remove any anonymous users that could potentially access your database.
  3. You will be asked if you want to disallow login remotely for the root user. It's generally a good idea to answer 'Y' to prevent remote access using the root account.
  4. The script will then prompt you to remove the test database and privileges. Answer 'Y' to remove the test database, which is not needed in a production environment.
  5. Finally, the script will reload the privilege tables to apply the changes you made.

By following these steps, you will enhance the security of your MySQL installation and reduce the risk of unauthorized access to your database.

Connect to MySQL and Verify Installation

Now that you have successfully installed MySQL on your AlmaLinux 9 server, it's time to connect to the MySQL server and verify that everything is working as expected. Follow the steps below to connect to the MySQL shell:

  1. Open a terminal on your AlmaLinux 9 server.
  2. Type the following command and press Enter:
  3. You will be prompted to enter the MySQL root password. Type the password and press Enter.

Once you have entered the correct password, you will be connected to the MySQL shell, and you will see a prompt that looks like this:

mysql>

At this point, you can run various MySQL commands to manage your databases and execute SQL queries. To test the installation, you can run the following command to display the version of MySQL installed on your server:

SELECT VERSION();

If everything is working correctly, you should see the version number displayed in the output. This confirms that your MySQL installation on AlmaLinux 9 is functioning properly.

Additional Packages from MySQL Website

If you require the latest version of MySQL server that is not available in the AppStream repository, you have the option to download the packages directly from the MySQL website. This allows you to have more control over the installation process and choose specific packages based on your requirements.

To download the necessary RPM packages from the MySQL website, follow these steps:

  1. Visit the MySQL website and navigate to the Downloads section.
  2. Choose the desired version of MySQL server for AlmaLinux 9 and click on the "Download" button.
  3. Select the appropriate package for your system architecture (x86_64 or aarch64) and click on the download link.
  4. Save the RPM package to a location on your AlmaLinux 9 server.
  5. Open a terminal and navigate to the directory where the RPM package is saved.
  6. Run the following command to install the package: sudo dnf install package_name.rpm
  7. Follow the prompts to complete the installation process.

By downloading the packages directly from the MySQL website, you can ensure that you are using the latest version of MySQL server and have access to all the features and updates that are not yet available in the AppStream repository.

Uninstall MySQL on AlmaLinux 9

If for any reason you want to remove MySQL from your AlmaLinux 9 server, you can do so by following a few simple steps. Uninstalling MySQL ensures that all software components associated with the database server are removed from your system.

To uninstall MySQL on AlmaLinux 9, open a terminal and run the following command:

sudo dnf remove mysql-server

This command will prompt you to confirm the removal of MySQL and its related packages. Press 'y' and then 'Enter' to proceed with the uninstallation process.

Once the uninstallation is complete, you can verify that MySQL has been successfully removed by running the following command:

mysql --version

If MySQL has been uninstalled properly, this command will return an error message indicating that the MySQL client is not installed. This confirms that the uninstallation was successful and that MySQL is no longer present on your AlmaLinux 9 server.

Conclusion

Installing MySQL on AlmaLinux 9 is a straightforward process that can be done using the DNF package manager or by downloading packages from the MySQL website. By following the step-by-step guide provided in this article, you can have a fully functional MySQL database server up and running on your AlmaLinux 9 server.

Remember to secure your installation and connect to the MySQL server to verify its functionality. Securing your MySQL installation will help protect it from unauthorized access and ensure the safety of your data. The mysql_secure_installation script provided by MySQL can assist you in this process. Once your installation is secure, you can connect to the MySQL server using the provided command and verify that everything is working correctly.

Whether you choose to install MySQL using the DNF package manager or download packages directly from the MySQL website, you have options that suit your needs. The flexibility of choosing specific packages allows you to customize your installation based on your requirements. If you ever need to uninstall MySQL from your AlmaLinux 9 server, simply run the provided command to remove it.

With MySQL installed and configured on AlmaLinux 9, you can now enjoy the benefits of having a powerful and reliable database server at your disposal. Whether you're using MySQL for a personal project or in a professional setting, this guide has provided you with the necessary knowledge to get started. Happy MySQL-ing!

Sys Admin

Sys Admin

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