How can I install MySQL on Rocky Linux 9?
The introductory section
MySQL is a database management system that is open-source and commonly found in the LEMP stack, which includes Linux, Nginx, MySQL/MariaDB, and PHP/Python/Perl. It enables the management and retrieval of data by implementing the relational model and utilizing SQL.
This guide illustrates the process of MySQL version 8 installation on a Rocky Linux 9 server.
Requirements
In order to finish this tutorial, you will require a Rocky Linux 9 server. It is essential to have a non-root user with admin privileges on this server and a firewalld configured firewall. For instructions on setting this up, refer to our Initial Server Setup guide for Rocky Linux 9.
First, install MySQL.
MySQL version 8 can be found in the default repositories of Rocky Linux 9.
To install the mysql-server package along with its dependencies, run the given command.
- sudo dnf install mysql-server
Once prompted, press the letter y followed by the ENTER key to confirm your intention to proceed.
. . . Install 49 Packages Total download size: 46 M Installed size: 252 M Is this ok [y/N]: y
After installing MySQL on your server, it is not yet functioning. The recently installed package sets up MySQL to run as a systemd service, specifically named mysqld.service. To utilize MySQL, you must initiate it using the systemctl command.
- sudo systemctl start mysqld.service
To ensure the proper functioning of the service, execute the given command. It’s important to note that for most systemctl commands, such as start and status mentioned here, you can omit .service after the service name.
- sudo systemctl status mysqld
If MySQL starts up without any issues, the output will indicate that the MySQL service is currently active.
● mysqld.service – MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2020-03-12 14:07:41 UTC; 1min 7s ago Main PID: 15723 (mysqld) Status: “Server is operational” Tasks: 38 (limit: 5056) Memory: 474.2M CGroup: /system.slice/mysqld.service └─15723 /usr/libexec/mysqld –basedir=/usr Mar 12 14:07:32 rocky9-mysql systemd[1]: Starting MySQL 8.0 database server… Mar 12 14:07:32 rocky9-mysql mysql-prepare-db-dir[15639]: Initializing MySQL database Mar 12 14:07:41 rocky9-mysql systemd[1]: Started MySQL 8.0 database server.
Afterward, use this command to ensure that MySQL starts every time the server is powered on:
- sudo systemctl enable mysqld
Note
sudo systemctl disable mysqld
Your server now has MySQL installed, running, and enabled. In the next step, we will explain the process of enhancing your database’s security by using a preinstalled shell script for your MySQL instance.
Step 2 – Ensuring the security of MySQL
MySQL comes with a security script which enables you to modify certain default configuration options with the aim of enhancing the security of MySQL.
To utilize the security script, execute the following directive:
- sudo mysql_secure_installation
You will be guided through a sequence of prompts that inquire about your willingness to modify the security options of your MySQL installation. The initial prompt will inquire if you wish to establish the Validate Password Plugin, which is useful for evaluating the robustness of your MySQL password.
If you decide to establish the Validate Password Plugin, you will be prompted to select a password validation level. The highest level, which can be chosen by entering 2, will demand that your password consists of a minimum of eight characters and comprises a combination of uppercase letters, lowercase letters, numbers, and special characters.
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
No matter if you decide to install the Validate Password Plugin, the next step will require you to create a password for the MySQL root user. Please provide and confirm a strong password of your preference.
Please set the password for root here. New password: Re-enter new password:
If you have utilized the Validate Password Plugin, you will be provided with an evaluation of the potency of your recently created password. Following that, the script will inquire whether you wish to proceed with the password you have just inputted or if you prefer to input a different one. If you are content with the strength of the password you have just entered, type ‘Y’ to proceed with the script.
Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Afterwards, you may select Y and press ENTER to accept the default settings for all the following inquiries. This action will eliminate certain anonymous users and the test database, deactivate remote root logins, and apply these updated regulations to ensure that MySQL promptly acknowledges your modifications.
After completing the installation and security setup of MySQL on your Rocky Linux 9 server, we now move on to the final step of testing the accessibility and functionality of the database.
Step 3 involves the testing of MySQL.
To confirm your installation and obtain details about it, you may connect using the mysqladmin tool, which is a client enabling the execution of administrative commands. Use the given command to connect to MySQL as the root user (-u root), prompt for a password (-p), and obtain the version of the installation.
- mysqladmin -u root -p version
You will observe a result that resembles this.
Provide me with one alternative phrasing for the term “Output” in a native manner:
Result
mysqladmin Ver 8.0.28 for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 8.0.28
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 1 min 11 sec
Threads: 2 Questions: 16 Slow queries: 0 Opens: 133 Flush tables: 3 Open tables: 49 Queries per second avg: 0.225
This signifies that your installation was completed successfully.
To initiate a connection with MySQL and start adding data, execute the given command.
- mysql -u root -p
Similar to the previous mysqladmin command, this command contains the -u option, enabling you to select the desired user for connection (in this case, root), along with the -p option, which prompts you to enter the user password you established in the preceding step.
Once you have entered the password for your root MySQL user, the MySQL prompt will appear.
You can commence utilizing your MySQL installation to generate and load databases, as well as initiate querying.
In summary,
Once you have completed this tutorial, MySQL will be installed and protected on your Rocky Linux 9 server. Afterward, you can proceed with installing Nginx and PHP to establish a fully functional LEMP stack on your server.
If you’re interested in expanding your knowledge on MySQL, we strongly recommend going through the official documentation.
More tutorials
sudo for new user with privileges on Rocky Linux 8(Opens in a new browser tab)
SSH Example Tutorial for Expect Script(Opens in a new browser tab)
Guidelines for Setting up SSL on Tomcat(Opens in a new browser tab)
How to Maintain Updated Rocky Linux 9 Servers(Opens in a new browser tab)
Python 3 installing on Rocky Linux 9(Opens in a new browser tab)