main logo

How to Install MySQL on Fedora 40

How to Install MySQL on Fedora 40

Fedora 40, known for its cutting-edge features and close ties to the upstream Linux community, offers a dynamic environment for developers and system administrators. This guide provides a detailed walkthrough for installing MySQL Community Server on a Fedora 40 system. We will cover updating your system, installing the MySQL server packages (typically from the official MySQL Yum repository for Fedora, or system repositories if up-to-date), performing essential security configurations, and managing the MySQL service. For those seeking comprehensive server management or specialized Linux Server Support, professional services can offer significant advantages.

MySQL is a globally recognized open-source relational database management system (RDBMS), crucial for a wide range of applications requiring robust and scalable data storage. By following this tutorial, you will set up a functional and secure MySQL installation on your Fedora 40 server.

Note on Fedora Release Cycle: Fedora has a relatively short release cycle (approximately 6 months per release, with each release supported for about 13 months). While this guide is for Fedora 40, users should be mindful of the EOL dates and plan upgrades accordingly for production systems.

Prerequisites

  • A server running Fedora 40.
  • A non-root user account with sudo privileges.
  • Access to a terminal or command-line interface (CLI).

Before starting, ensure your Fedora 40 system is fully updated and you have a sudo-enabled user. Standard Fedora initial server setup guides can provide instructions if needed.

Step 1 — Updating System Packages

Before installing new software, especially on a fast-moving distribution like Fedora, it is crucial to ensure your system packages are up to date.

sudo dnf upgrade --refresh

This command refreshes the metadata and upgrades all installed packages.

Step 2 — Installing MySQL

Fedora often includes recent versions of MySQL in its default repositories. Alternatively, for the latest versions or specific series, using the official MySQL Yum repository is recommended.

Method 1: Using Fedora Repositories (Check Availability)

First, check if a suitable MySQL package (e.g., community-mysql-server or mysql-community-server) is available and recent enough for your needs:

sudo dnf search mysql-server

If a suitable version is available, you can install it directly:

sudo dnf install community-mysql-server # Or the appropriate package name found

Method 2: Using the Official MySQL Yum Repository (Recommended for Latest Versions)

  1. Download the MySQL Yum Repository Setup RPM:
    Go to the MySQL Yum Repository download page and download the appropriate RPM package for Fedora (e.g., mysql80-community-release-fc40-...noarch.rpm or a newer one for MySQL 8.x LTS like 8.4.x if available for Fedora 40).

    “`bash

    Example for MySQL 8.0 – replace with the correct current URL/filename

    wget https://dev.mysql.com/get/mysql80-community-release-fc40-1.noarch.rpm
    “`
    (Note: The exact filename will change with versions. Always get the latest from the MySQL site.)

  2. Install the Repository RPM:
    bash
    sudo dnf install mysql80-community-release-fc40-1.noarch.rpm # Adjust filename as needed

    This command adds the MySQL Yum repository to your system and imports the GPG key.

  3. Install MySQL Server:
    Now, install MySQL server using dnf from the newly added repository:
    bash
    sudo dnf install mysql-community-server

After the installation is complete using either method, start the MySQL service:

sudo systemctl start mysqld

Verify that the service has started correctly:

sudo systemctl status mysqld

The output should show the service as active (running).

MySQL (when installed from the official repository) generates a temporary root password during installation. This password is logged in the MySQL error log. You can retrieve it using grep:

sudo grep 'temporary password' /var/log/mysqld.log

Carefully note this temporary password for the next step. If installed from Fedora’s native repositories, the behavior might differ (e.g., it might not set a temporary password and might use socket authentication for root initially, similar to Debian/Ubuntu).

Step 3 — Securing MySQL

MySQL includes a security script, mysql_secure_installation, which is essential for hardening your MySQL server. This script will guide you through setting a new root password, removing anonymous users, disallowing remote root logins, and removing the test database.

Run the script with sudo privileges:

sudo mysql_secure_installation
  1. Enter Temporary/Current Password: If a temporary password was set, you will be prompted for it. If not (e.g., if socket authentication is used for root and no password was set), the script might behave differently or ask if you want to set a root password.
  2. VALIDATE PASSWORD Component: You will be asked if you want to set up the VALIDATE PASSWORD component. This is highly recommended for production to enforce strong password policies. If you choose Yes (Y), select a password validation policy level (0 for LOW, 1 for MEDIUM, or 2 for STRONG).
  3. Set New Root Password: You will be prompted to set and confirm a new password for the MySQL root user. Choose a strong, unique password.
  4. Security Questions: The script will then ask a series of yes/no questions:
    • Remove anonymous users? (Recommended: Yes)
    • Disallow root login remotely? (Recommended: Yes)
    • Remove test database and access to it? (Recommended: Yes)
    • Reload privilege tables now? (Recommended: Yes)

Completing these steps is crucial for a secure MySQL deployment. For advanced security configurations or ongoing database management, consider seeking professional MySQL support.

Step 4 — Testing MySQL

After securing your MySQL installation, test if you can log in with the new root password.

mysql -u root -p

Enter the new root password you set. A successful login will bring you to the MySQL monitor prompt (mysql>).

Run a simple command to verify, such as checking the MySQL version:

SELECT VERSION();

To exit the MySQL monitor, type:

EXIT;

Step 5 — Managing the MySQL Service

The MySQL service on Fedora 40 is managed using systemctl.

  • Start MySQL:
    bash
    sudo systemctl start mysqld
  • Stop MySQL:
    bash
    sudo systemctl stop mysqld
  • Restart MySQL:
    bash
    sudo systemctl restart mysqld
  • Check MySQL Status:
    bash
    sudo systemctl status mysqld
  • Enable MySQL on Boot: To have MySQL start automatically when the server boots:
    bash
    sudo systemctl enable mysqld
  • Disable MySQL on Boot: To prevent MySQL from starting automatically:
    bash
    sudo systemctl disable mysqld

Conclusion

You have successfully installed and secured MySQL on your Fedora 40 server. Your database server is now ready for your applications. Given Fedora’s release cycle, remember to plan for regular system and MySQL upgrades to maintain support and security.

For further learning and related guides, consider the following:

Effective database management is key for application performance and data security. If your business requires expert assistance with database administration, or if you are looking for comprehensive Managed IT Services, Medha Cloud offers a range of solutions to support your infrastructure. For Managed Service Providers (MSPs), Medha Cloud also provides white-label managed IT services, allowing you to expand your service offerings seamlessly.

Medha Cloud
Medha Cloud
Medha Cloud, a leading multi-cloud service provider, focuses on cloud computing and digital transformation. Every article published under the Medha Cloud brand is a collaborative effort by our team. We are committed to sharing insights, best practices, how-tos, reviews, and real-world examples to help organizations stay ahead of the curve and thrive in the digital age
Share
Contents

Related Articles

medhacloud logo
USA:
Medha Cloud Solutions LLC
30 N Gould St Ste R, Sheridan, WY 82801,
Phone: +1 646 775 2855

India:
Medha Cloud Solutions Private Limited
#74, 7th Cross, Krishna Garden InCity Layout. Chikka Kammanahalli, Banneraghatta Road, Bangalore 560083
Phone:+91 93536 44646

E-Mail: sales@medhahosting.com
©Medha Cloud 2024. All rights reserved.