Follow this step-by-step guide to successfully install and secure MySQL 8.4 on Red Hat Enterprise Linux 10. Learn how to troubleshoot common setup errors and verify your installation.
If you're setting up a new application on Red Hat Enterprise Linux (RHEL) that requires a database, MySQL 8.4 is a powerful and popular choice. This guide will walk you through the entire process, from adding the official MySQL repository to securing your installation, using simple, copy-paste commands.
Step 1: Preparing Your System and Installing MySQL
Before installing new software, it's a good practice to ensure your system is up to date.
Update System Packages:
sudo yum update
This command refreshes your system's package list and upgrades existing software to their latest versions.
Download and Add the MySQL Yum Repository:
Adding the official repository ensures you get the latest version of MySQL directly from Oracle.
sudo yum install wget
cd /tmp/
wget https://dev.mysql.com/get/mysql84-community-release-el10-2.noarch.rpm
sudo yum localinstall mysql84-community-release-el10-2.noarch.rpm
The repository package also handles importing the necessary GPG key to verify package integrity .
Install MySQL Server:
With the repository in place, you can now install the MySQL server and its dependencies.
sudo yum install mysql-community-server
This installs the mysql-community-server package along with required components like the client and common files .
Step 2: Starting MySQL and Dealing with the Temporary Password
After installation, you need to start the service and complete the initial setup.
Start and Enable MySQL Service:
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo systemctl status mysqld
The enable command ensures MySQL starts automatically upon system boot. Checking the status confirms the service is running properly, as shown by Active: active (running) in your output.
Retrieve the Temporary Root Password:
Upon first start, MySQL generates a temporary password for the root user. This is a security feature, and the password is logged for you to find.
sudo grep 'temporary password' /var/log/mysqld.log
Your log showed: A temporary password is generated for root@localhost: J5/TzPeyK>ra
Step 3: Securing Your MySQL Installation
This is a crucial step to protect your database. MySQL includes a security script to guide you through this process.
Run the Security Script:
mysql_secure_installation
Follow the Interactive Prompts:
Enter the temporary password you retrieved in the previous step.
Set a new, strong root password. MySQL's validate_password component is installed by default and requires a robust password .
Remove anonymous users. This enhances security by deleting default test accounts .
Disallow remote root login? You chose to skip this (... skipping.), which is fine if you need to connect to the database remotely. For maximum security on a local-only server, it's better to disallow it.
Remove the test database. This eliminates a default database that is not needed for production .
Reload privilege tables. This applies all the security changes immediately.
Step 4: Verifying the Installation
Finally, log in to your new MySQL server to confirm everything is working.
mysql -u root -p
After entering your new password, run:
SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
You should see the default system databases listed, confirming a successful installation.