In this tutorial, we will show you how to install MySQL on AlmaLinux 9. For those of you who didn’t know, MySQL is a freely available open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). It is one of the most widely used database software for several well-known applications. MySQL is used for data warehousing, e-commerce, and logging applications, but its more commonly used feature is web database storage and management.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MySQL database on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux.
- A server running one of the following operating systems: AlmaLinux 9.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install MySQL on AlmaLinux 9
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf clean all sudo dnf update sudo dnf groupinstall "Development Tools"
Step 2. Installing MySQL on AlmaLinux 9.
By default, MySQL is available on the AlmaLinux 9 base repository. Simply install the MySQL server package by using the
sudo dnf install mysql mysql-server
Next, start the MySQL service and enable it to automatically start on boot by running the following command:
sudo systemctl enable --now mysqld sudo systemctl start mysqld sudo systemctl status mysqld
Confirm the installation and check the installed build version of MySQL:
Step 3. Secure MySQL on AlmaLinux 9.
By default, MySQL is not hardened. You can secure MySQL using the
mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:
Use the following options for the prompt:
Enter current password for root (enter for none): Just press the Enter Set root password? [Y/n]: Y New password: Enter your password Re-enter new password: Repeat your password Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
Once secured, you can log in to the MySQL shell using the following command:
sudo mysql -u root -p
To create a database, database user, and grant all privileges to the database user run the following commands:
MySQL [(none)]> CREATE DATABASE test_db; MySQL [(none)]> CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'your-password'; MySQL [(none)]> GRANT ALL ON tests_db.* TO 'test_user'@'localhost'; MySQL [(none)]> FLUSH PRIVILEGES; MySQL [(none)]> EXIT
Congratulations! You have successfully installed MySQL. Thanks for using this tutorial for installing the MySQL database server on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official MySQL website.