Install MySQL 8 on AlmaLinux 8

Install MySQL 8 on AlmaLinux 8 using this step by step guide. Before we begin, we need to make sure the system has the latest updates. Use the following command to check for updates.

sudo yum update -y

Enable MySQL Module

We need to enable MySQL Upstream Module, use the following command to enable it.

sudo yum module list mysql
sudo yum module enable mysql:8.0

You will be requested on the terminal window to confirm this action. Please do so by typing "y" and pressing the return or enter key to continue.

Now that MySQL is installed, it must be enabled to start automatically at boot. Enable MySQL using the following command.

sudo systemctl enable mysqld

Start MySQL

Start MySQL daemon using the following command.

sudo systemctl start mysqld

Verify that MySQL is active and running by executing the following command.

sudo systemctl status mysqld

You should see an active status in green color, confirming that MySQL is installed and running successfully.

Secure MySQL

MySQL is installed with default settings that could be exploited by hackers. To finalize the installation, we must harden MySQL and secure it. Run the following command to secure MySQL.

sudo mysql_secure_installation

You will be prompted to use the VALIDATE_PASSWORD plugin which determines the level of password strength.

Continue the setup process by typing "y" and pressing the Enter on your keyboard. The plugin provides 3 password policy levels namely: LOW, MEDIUM & STRONG.

Type 2 for STRONG password policy and press the Enter key on your keyboard.

Set a strong MySQL root password in accordance with the password level selected. The strong password must have a minimum of 8 characters consisting of numeric, upper case letters, lower case letters, and special characters.

To proceed with the set password press "y" to continue. Otherwise, press "n" to go back and make the required adjustments.

Press "y" on the remaining prompts to harden the MySQL installation. The script will do the following:

  • Remove anonymous users
  • Prevent the root user from logging in remotely
  • Remove the test database

The MySQL database should be purged and deleted before proceeding into a production environment.

Connect to MySQL

Start connecting to MySQL using the following command. This command will use the MySQL client to connect as the root user. You will be asked to type your password to authenticate.

sudo mysql -u root -p

Congratulation, now you have setup MySQL 8 successfully on AlmaLinux.