MySQL is an open-source relational database management system that is widely used for storing and organizing data. Red Hat Enterprise Linux (RHEL) and CentOS Stream are two popular Linux distributions used by many developers and system administrators. In this article, we will be discussing how to install MySQL 8.0 on RHEL and CentOS Stream 9.
Prerequisites
- RHEL or CentOS Stream 9 operating system installed on your computer
- Root user access or a user with sudo privileges
Step 1: Adding the MySQL Repository
The first step in installing MySQL 8.0 on RHEL and CentOS Stream 9 is to add the official MySQL repository to your system. This will ensure that you are getting the latest version of MySQL and that you receive automatic updates.
To add the MySQL repository, open the terminal and download the repository configuration package:
wget https://repo.mysql.com//mysql80-community-release-el9-1.noarch.rpm
Once the download is finished, install it:
sudo dnf install mysql80-community-release-el9-1.noarch.rpm
Step 2: Installing MySQL 8.0
Now that the repository has been added to your system, you can proceed to install MySQL 8.0 by using the following command:
sudo dnf install mysql-community-server
After the installation is complete, start the MySQL service by using the following command:
sudo systemctl start mysqld
Step 3: Securing MySQL
By default, MySQL is not secured when it is first installed. During the installation, a temporary password is set to root account. You can get the password from log file using the following command:
grep 'A temporary password is generated' /var/log/mysqld.log | tail -1
2023-02-07T07:56:14.276442Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ZydSrO9cEw>9
In the above output, the current password is `ZydSrO9cEw>9`.
Then, you will need to run the following command to secure it.
sudo mysql_secure_installation
You will be prompted to set a root password for MySQL and answer a few security questions. Answer these questions according to your preferences.
- Enter password for user root: [Enter temporary password]
- New password: [Enter a new password]
- Re-enter new password: [Re-enter new password]
- Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
- Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
- Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
- Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Once completed, MySQL is now secured.
Step 4: Testing the Installation
To test the installation, you can log into the MySQL shell by using the following command:
mysql -u root -p
Enter the root password you set during the security process, and you should be able to access the MySQL shell.
Output:Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.32 MySQL Community Server - GPL 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>
Conclusion
In conclusion, installing MySQL 8.0 on RHEL and CentOS Stream 9 is a straightforward process that can be completed in a few simple steps. By following this guide, you will have a working installation of MySQL 8.0 on your RHEL or CentOS Stream 9 system.