Introduction
Developers and system administrators often encounter issues during the installation and configuration of MySQL on Red Hat Enterprise Linux 8 (RHEL8). One common issue is setting the root password during the MySQL secure installation process. In this article, we will cover how to solve this issue and ensure a secure MySQL installation on RHEL8.
Prerequisites
Before we begin, ensure the following:
- A fresh installation of RHEL8
- MySQL server is not yet installed or configured
- Root user access to the RHEL8 system
Installing MySQL
To install MySQL on RHEL8, follow these steps:
- Update the package repository:
- Install the MySQL server:
- Start and enable the MySQL service:
sudo yum update -y
sudo yum install mysql-server -y
sudo systemctl start mysqld
sudo systemctl enable mysqld
Running mysql_secure_installation
By default, the MySQL installation process includes the mysql_secure_installation script. This script is designed to help secure the MySQL installation by setting the root password, removing anonymous users, and disabling remote access, among other things. However, if you did not set the root password during the installation process, you will be prompted to do so when you run the script again.
Setting the root password
To set the root password using the mysql_secure_installation script, follow these steps:
- Connect to the MySQL server as the root user:
- Enter the current root password (which is blank by default).
- Press Enter to continue.
- Set a new root password:
- Exit the MySQL server:
sudo mysql -u root -p
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
EXIT;
Replace "new_password" with your desired root password.
Alternative method: Setting the root password manually
If you prefer not to use the mysql_secure_installation script, you can set the root password manually using the MySQL command-line client. Follow these steps:
- Connect to the MySQL server as the root user:
- Enter the current root password (which is blank by default).
- Press Enter to continue.
- Set a new root password:
- Exit the MySQL server:
sudo mysql -u root -p
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
EXIT;
In this article, we covered how to solve the issue of not being able to set the root password during the MySQL secure installation process on RHEL8. We explored two methods: using the mysql_secure_installation script and setting the root password manually using the MySQL command-line client. Both methods ensure a secure MySQL installation on RHEL8.