This article will walk us through How To Install MySQL 8.0 on Rocky Linux 9|AlmaLinux 9.
The widely used LEMP (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack includes MySQL, an open-source database management system. It uses the relational paradigm and Structured Query Language (SQL) to manage and query data. The most recent stable version of MySQL was made available on July 26, 2022, and is version 8.0.30.
Features of MySQL 8.0
Important features of the most recent release of MySQL include;
- Enhancements to InnoDB and XML.
- Transactional data dictionary.
- Native JSON data support and enhanced document storage features.
- Table expressions that are common.
- The error log has two improvements, lower verbosity and error numbers.
Install MySQL 8.0 on Rocky Linux 9|AlmaLinux 9
Follow the below steps to install MySQL 8.0 on Rocky Linux 9|AlmaLinux 9 system.
#1. Update the System
It is always advised to start with updating the system packages while installing software packages in Linux systems;
sudo dnf update
#2. Enable the MySQL Upstream Module
As we proceed, we must enable the MySQL 8.0 module that the AppStream repository offers. The AppStream repositories are by default enabled;
sudo dnf whatprovides mysql-server
Output;
Last metadata expiration check: 22:22:58 ago on Sun 21 May 2023 05:12:51 AM EAT.
mysql-server-8.0.32-1.el9_2.x86_64 : The MySQL server and related files
Repo : appstream
Matched from:
Provide : mysql-server = 8.0.32-1.el9_2
#3. Install MySQL 8.0 on Rocky Linux 9|AlmaLinux 9
Execute the below command to install MySQL 8.0 on Rocky Linux 9|AlmaLinux 9;
sudo dnf install mysql-server
Output;
Dependencies resolved.
==========================================================================================================================================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================================================================================================================================
Installing:
mysql-server x86_64 8.0.32-1.el9_2 appstream 17 M
Installing dependencies:
mariadb-connector-c-config noarch 3.2.6-1.el9_0 appstream 9.8 k
mecab x86_64 0.996-3.el9.3 appstream 347 k
mysql x86_64 8.0.32-1.el9_2 appstream 2.7 M
mysql-common x86_64 8.0.32-1.el9_2 appstream 70 k
mysql-errmsg x86_64 8.0.32-1.el9_2 appstream 487 k
mysql-selinux noarch 1.0.5-1.el9_0 appstream 35 k
protobuf-lite x86_64 3.14.0-13.el9 appstream 231 k
Transaction Summary
==========================================================================================================================================================================================================================================
Install 8 Packages
Total download size: 21 M
Installed size: 179 M
Is this ok [y/N]: y
Now check the installed version;
$ mysql --version
mysql Ver 8.0.32 for Linux on x86_64 (Source distribution)
#4. Enable and Start MySQL 8.0 on Rocky Linux 9|AlmaLinux 9
Any operations using the MySQL database server must first be initiated by starting the service. However, let’s enable and start it to launch at boot time as seen below;
sudo systemctl enable mysqld
sudo systemctl start mysqld
Check its status;
sudo systemctl status mysqld
Output;
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
Active: active (running) since Mon 2023-05-22 03:40:07 EAT; 3s ago
Process: 4042 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Process: 4064 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Main PID: 4140 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 23046)
Memory: 440.8M
CPU: 6.886s
CGroup: /system.slice/mysqld.service
└─4140 /usr/libexec/mysqld --basedir=/usr
May 22 03:39:45 example.tutornix.com systemd[1]: Starting MySQL 8.0 database server...
May 22 03:39:45 example.tutornix.com mysql-prepare-db-dir[4064]: Initializing MySQL database
May 22 03:40:07 example.tutornix.com systemd[1]: Started MySQL 8.0 database server.
#5. Secure MySQL 8.0 on Rocky Linux 9|AlmaLinux 9
You should run the security script that comes with the database management system when installing MySQL for the first time. This script modifies some less secure default settings, such as those that forbid remote root logins and get rid of test users.
Open the MySQL prompt by typing;
sudo mysql
Sample output;
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distribution
Copyright (c) 2000, 2023, 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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
The following ALTER USER command can be used to change the root user’s authentication method to one that uses a password. In the instance given below, the authentication method is switched to mysql native password;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Ensure to replace ‘password‘ with your own password.
Sample output;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'myStr0nP@ssW0rd';
Query OK, 0 rows affected (0.58 sec)
Exit the MySQL prompt after making this change;
mysql> exit;
Bye
Protecting the recently installed MySQL database server is the final step. By using the mysql secure installation script, you can add some security. The VALIDATE PASSWORD plugin, which evaluates the strength of your passwords, will be necessary for you to use.
Type “Y” and press ENTER to confirm that you wish to install the plugin. Three distinct password security levels are available with the plugin: LOW, MEDIUM, and STRONG. Select STRONG;
$ sudo mysql_secure_installation
Sample output;
Securing the MySQL server deployment.
Enter password for user root: <ENTER-ROOT-PASSWORD> #the root password you set above
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
Using existing password for root.
Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password: <ENTER-NEW-PASSWORD>
Re-enter new password: <RE-ENTER-NEW-PASSWORD>
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
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
Conclusion
Congratulations! MySQL 8.0 has been successfully installed on Rocky Linux 9|AlmaLinux 9. We appreciate you utilizing this guide to install MySQL 8.0 on your Rocky Linux 9|AlmaLinux 9 system.
Read more about MySQL here;
Check also these tutorials;