Installing MySQL 8.4 on AlmaLinux 9
Install MySQL Server 8.4 on AlmaLinux 9 using the official repository. Configure the service, create a root password, and start the server.
Install MySQL Server 8.4 on AlmaLinux 9 using the official repository. Configure the service, create a root password, and start the server. These steps apply to AlmaLinux 9 systems with a standard installation.
Prerequisites
- AlmaLinux 9 with root access or a sudo user.
- At least 2 GB of available RAM.
- 500 MB of free disk space for the data directory.
- Internet connection to download the repository keys and packages.
Step 1: Install the MySQL repository
Add the official MySQL repository to your system. This ensures you get the latest stable version and security updates. Run the following command to add the repository and import the GPG key.
sudo dnf install -y https://dev.mysql.com/get/mysql84-community-release-el9.rpm
Verify that the repository was added successfully by listing available MySQL packages.
dnf list available | grep mysql-community-server
You should see a list of packages including mysql-community-server-8.4.x.
Step 2: Install MySQL Server
Install the MySQL Server package along with the client tools. This installs the core server, the command-line client, and the utilities needed to manage the database.
sudo dnf install -y mysql-community-server
Wait for the installation to complete. The process downloads the binaries and configures the initial settings automatically.
Step 3: Configure the MySQL service
Start the MySQL service and enable it to start on boot. This ensures the database is ready to accept connections immediately after installation.
sudo systemctl start mysqld
sudo systemctl enable mysqld
Check the status of the service to confirm it is running. You should see "active (running)" in the output.
sudo systemctl status mysqld
Step 4: Set the root password
Generate a temporary password for the root user. This password is required to log in and set a permanent password. Locate the temporary password in the system logs.
sudo grep 'temporary password' /var/log/mysqld.log
Copy the password string that appears after "temporary password". You will need this to log in as root.
Log in to the MySQL server using the temporary password. Replace YOUR_TEMP_PASSWORD with the actual string from the log.
mysql -u root -pYOUR_TEMP_PASSWORD
Once logged in, run the following SQL command to set a new, strong password for the root user. Replace NEW_PASSWORD with your chosen password.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
Flush the privileges to ensure the changes take effect immediately.
FLUSH PRIVILEGES;
Exit the MySQL client by typing exit. You can now log in using your new password.
Verify the installation
Log in to the MySQL server using your new root password. Verify that the server is running and the user has the correct privileges.
mysql -u root -p
Run the following SQL query to confirm the installation and version.
SELECT VERSION();
The output should display "8.4.x" as the version number. This confirms that MySQL 8.4 is installed and functioning correctly.
Version
-------
8.4.0
Check the status of the service one more time to ensure it remains active.
systemctl status mysqld
Troubleshooting
Here are common errors you might encounter and how to fix them.
Error: "Failed to start MySQL Server"
This error often occurs if the data directory is missing or has incorrect permissions. Check the error log at /var/log/mysqld.log for details. Ensure the directory exists and belongs to the mysql user.
sudo chown -R mysql:mysql /var/lib/mysql
Error: "Access denied for user 'root'@'localhost'"
This happens if you try to log in with a password that was not set or if the root user was locked. Use the temporary password found in /var/log/mysqld.log to log in and reset the password as shown in Step 4.
Error: "Cannot create/write to the file '/var/lib/mysql/..."
This indicates a permission issue with the data directory. Ensure the directory exists and is owned by the mysql user. Run the chown command above to fix ownership.
Error: "The server is not running"
If the service fails to start, check if the port 3306 is in use by another process. Run sudo systemctl stop mysqld to stop any conflicting services. Then restart the service with sudo systemctl start mysqld.