Home MySQL How to Install and Secure MySQL on Rocky Linux

How to Install and Secure MySQL on Rocky Linux

Brief: This article guide takes us through the installation, configuration, and testing of MySQL database server software on a Rocky Linux distribution.

Independently, MySQL is an ideal open-source database management software. Dependently, it completes the LEMP stack by linking up with Linux, Nginx, and PHP/Python/Pearl.

With MySQL, data query and management are achieved via the implementation of SQL (Structured Query Language) and relational models.

This article guide will walk us through the installation of the latest MySQL version release on Rocky Linux 9 and Rocky Linux 8.

Step 1: Installing MySQL on Rocky Linux

An updated Rocky Linux system provides the best performance experience for MySQL.

$ sudo dnf update 

We will use Rocky Linux’s default repository to install the mysql-server package together with its dependencies through the execution of the following command:

$ sudo dnf install mysql-server 
Install MySQL in Rocky Linux
Install MySQL in Rocky Linux

Confirm the installed MySQL database server version:

$ mysql --version 

mysql Ver 8.0.30 for Linux on x86_64 (Source distribution)

MySQL does not automatically start running after its installation, you need to start it, enable it to start at system startup, and verify the status by running the following commands.

$ sudo systemctl start mysqld 
$ sudo systemctl enable mysqld 
$ sudo systemctl status mysqld 
Check MySQL in Rocky Linux
Check MySQL in Rocky Linux

If you wish to disable MySQL from running after system startup, execute:

$ sudo systemctl disable mysqld

You might also need to restart MySQL after running the above command:

$ sudo systemctl restart mysqld

Step 2: Securing MySQL on Rocky Linux

To improve your MySQL security, you will need to change some of its default configuration options by executing the following MySQL security script.

$ sudo mysql_secure_installation 

You will be taken through a series of prompts that will enable you to choose whether to:

  • validate your password
  • remove anonymous users
  • disallow root login remotely
  • remove test database
  • reload table privileges
Secure MySQL in Rocky Linux
Secure MySQL in Rocky Linux

Step 3: Testing MySQL in Rocky Linux

You can verify your MySQL installation and view some of its information using the mysqladmin command, a client tool for performing administrative operations as shown.

$ mysqladmin -u root -p version

If you would like to connect to MySQL and start creating data on it, run the following:

$ mysql -u root -p 
Connect to MySQL in Rocky Linux
Connect to MySQL in Rocky Linux

From here, you should be able to create and load databases or execute queries related to your database projects.

[ You might also like: MySQL Database Commands Cheat Sheet for Linux ]

You can now explore the richness of MySQL database server on Rocky Linux.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.