How to Install MySQL on Rocky Linux and Alma Linux

In this tutorial we will learn How How to Install MySQL on Rocky Linux and Alma Linux. You will eventually need to configure a Rocky Linux database server. When you do, you may need to set it up so that other server/client may use it as a database server. This is an excellent technique to construct a single database server that can be utilized by several applications running on separate computers, or it may be used to offload database services to other servers.

One system might be used to host WordPress, while another machine could be used to direct that platform to a database. This has the advantage that you won’t lose your data in the event that the WordPress server goes down.

Pre-requisite

  • Rocky Linux 8 or 9 Host or Alma Linux 8 or 9. If you need to install OS refer How to Install Rocky Linux
  • User with sudo privileges

Installing MySQL packages

Run the below command to install the MySQL packages

Enable and restart the service

Allow the firewall

You must use the following command to open the appropriate port in the firewall in order to permit remote connections:

Securing the Database

Run the command

The VALIDATE PASSWORD COMPONENT will be shown to you first. When you see this, hit Y to confirm that only strong passwords are permitted.

After turning this on, you will need to choose one of the following password validation policy levels:

LOW: The password length needs to be at least eight characters long.

MEDIUM: The password must contain a mixture of mixed case, special characters, and numeric characters, and its length must equal or exceed eight characters.

STRONG: The password must be at least eight characters long, contain a mix of numeric and mixed case characters as well as special characters, and not be contained in a dictionary file.

Next, you’ll be prompted to enter 2 for STRONG, 1 for MEDIUM, and 0 for LOW

Type N if you want not to enable the policy. After that, you’ll need to enter and confirm the new password for the MySQL admin account. After completing that, select Y for the remaining inquiries.

Configuring the database

Open the configuration file

Add the following two lines at the bottom of that file:

Save and exit the file followed by restart of the service

Creating User in the database

Login to the MySQL

Create the appdb database

Let us now create users. We will create two users – one for localhost and other for remote access

Here, ‘mypass‘ is a unique and strong password

Let us give the users access to the appdb database

Flush the privileges and exit the MySQL console with:\

Testing the Access

You can log in to any machine within the same network (LAN) and run the below command to test if you are able to access the DB

Here, <SERVER_IP> is the IP of the Rocky Linux Host and hence replace it with your IP address. You will be prompted for the password for the ‘appuser‘ and you should be able to get the MYSQL console prompt.

Conclusion

With Rocky Linux, your MySQL database server is now up and running and accepting connections from IP addresses other than localhost. For more information refer the Official MySQL Documentation

Leave a comment