Installing MySQL community edition on new AlmaLinux 8 servers
This guide provides step-by-step instructions for installing the latest MySQL Community Edition on a new Core-Managed AlmaLinux 8 server that does not yet contain any data. Following these instructions on a server with existing data will lead to data loss.
DATA LOSS RISK:
These instructions are ONLY for new AlmaLinux 8 servers where a fresh MySQL installation is required and NO data currently exists. The initial steps involve removing any existing MySQL data directories. DO NOT proceed if your server contains live data you wish to keep. Liquid Web is not responsible for data loss if these instructions are misused on a production server with existing data.
Prerequisites
- A Core-Managed server running AlmaLinux 8.
- Root or sudo access to the server.
- The server must be new or in a state where existing MySQL data is not needed.
Installation steps
1. Prepare the server (ensure a clean slate)
These commands will remove any existing MySQL packages and data, preparing the system for a clean installation. This is crucial for avoiding conflicts.
sudo yum module -y disable mysql
sudo mv /var/lib/mysql /var/lib/mysql.lwbak
sudo mv /root/.my.cnf /root/.my.cnf.lwbak
sudo yum remove -y mysql mysql-community* mysql-devel mysql-server mysql-libs
Explanation of commands:
sudo yum module -y disable mysql: Disables the default MySQL module provided by AlmaLinux to prevent conflicts with the MySQL Community Edition.sudo mv /var/lib/mysql /var/lib/mysql.lwbak: Backs up the default MySQL data directory (if it exists).sudo mv /root/.my.cnf /root/.my.cnf.lwbak: Backs up the MySQL root user’s configuration file (if it exists). Note: This file may not be present on a brand new server, so the command might return a “No such file or directory” message, which is safe to ignore in this context.sudo yum remove -y mysql mysql-community* mysql-devel mysql-server mysql-libs: Removes any existing MySQL-related packages. The wildcardmysql-community*helps ensure all parts of a previous community edition install are removed.
2. Update your system
Ensure your server’s packages are up to date before proceeding.
sudo dnf update -y
Alternatively, you can use yum:
sudo yum update -y
3. Download the MySQL yum repository setup RPM
You need to download the official MySQL Yum repository configuration file. This file sets up your system to be able to download MySQL Community Edition directly from the MySQL developers.
- Navigate to the MySQL Community Downloads page for Yum Repositories: https://dev.mysql.com/downloads/repo/yum/
- On this page, look for the section titled “Red Hat Enterprise Linux 8 / Oracle Linux 8 (Architecture Independent), RPM Package”. MySQL 8.4 is the latest as of this writing, but select the version appropriate for your needs if different. The filename will typically be in the format
mysql<version>-community-release-el8-<revision>.noarch.rpm(e.g.,mysql84-community-release-el8-1.noarch.rpm). - Right-click on the “Download” button for the EL8 package and copy the link address.
- In your server terminal, use
wgetto download the file. Replace the example URL below with the link you copied:
wget https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm
The exact filename mysql84-community-release-el8-1.noarch.rpm is an example. Always get the latest link directly from the MySQL website as described above.
4. Verify the downloaded package (optional but recommended)
To ensure the package downloaded correctly and has not been corrupted, compare its MD5 checksum with the one provided on the MySQL download page (usually next to the download link).
First, calculate the MD5 checksum of your downloaded file (replace the filename if yours is different):
md5sum mysql84-community-release-el8-1.noarch.rpm
Compare the output (a string of numbers and letters) with the MD5 value displayed on the MySQL website. If they match, the download is valid. If not, please re-download the file.
5. Add the MySQL yum repository
Install the RPM package you just downloaded. This will add the MySQL repository to your system’s repository list.
sudo rpm -ivh mysql84-community-release-el8-1.noarch.rpm
(Again, replace mysql84-community-release-el8-1.noarch.rpm with the actual filename you downloaded.)
This command installs the repository. During the installation, it might also enable the latest MySQL Community Server stream (e.g., MySQL 8.4). If you need a different version (like 8.0), you might need to disable the default stream and enable a specific one using commands like: sudo yum module disable mysql-community sudo yum module enable mysql-community:8.0 However, for the latest version, this is usually not necessary.
6. Install MySQL server
Now, you can install the MySQL server package.
sudo yum install mysql-community-server -y
The system will download and install MySQL Server and its dependencies. Confirm any prompts by pressing Y if not using the -y flag already.
7. Start the MySQL service
Once the installation is complete, start the MySQL service:
sudo systemctl start mysqld
8. Check MySQL service status
Verify that the MySQL service is running:
sudo systemctl status mysqld
You should see output indicating that the service is active (running). Press q to exit the status view.
9. Enable MySQL to start on boot (recommended)
To ensure MySQL starts automatically when your server reboots, run:
sudo systemctl enable mysqld
10. Retrieve the temporary root password
MySQL 8.x generates a temporary root password during installation. You’ll need this to secure your MySQL installation.
sudo grep 'temporary password' /var/log/mysqld.log
The output will show a line similar to: ...root@localhost: YOUR_TEMPORARY_PASSWORD
Carefully copy this temporary password. You will need it in the next step.
For Core-Managed customers, Liquid Web Support may proactively store this temporary password in the Secure Notes section of your my.liquidweb.com account if the installation was assisted. If you performed this installation yourself, ensure you store this password securely until it’s changed.
11. Secure your MySQL installation
MySQL provides a script to perform several important security operations, such as setting a new root password, removing anonymous users, disallowing remote root login, and removing the test database. This step is critical for securing your MySQL server.
sudo mysql_secure_installation
The script will guide you through the following prompts:
- Enter password for user root: Paste the temporary password you retrieved in Step 9.
- VALIDATE PASSWORD component: You can choose to enable the Validate Password Component, which enforces strong password policies. Type
Yfor yes or any other key for no. If enabled, select a password strength level (0 for LOW, 1 for MEDIUM, 2 for STRONG). - New password for root: Enter your desired new root password. Make sure it’s strong and unique. Re-enter it when prompted.
- Remove anonymous users? (Recommended: Y)
- Disallow root login remotely? (Recommended: Y)
- Remove test database and access to it? (Recommended: Y)
- Reload privilege tables now? (Recommended: Y)
Once completed, your MySQL installation will be more secure.
12. Clean up backup directory
After confirming your new MySQL installation is working and you’ve secured it, you can remove the backup of the old MySQL data directory created in Step 1 (if it existed).
sudo rm -rf /var/lib/mysql.lwbak
sudo rm -f /root/.my.cnf.lwbak
Conclusion
You have now successfully installed and secured MySQL Community Edition on your AlmaLinux 8 server. You can connect to your MySQL server using the root account and the new password you set during mysql_secure_installation.
If you encounter any issues, please review the steps or contact Liquid Web support for assistance with your Core-Managed server.