FedoraRHEL Based

How To Install MySQL on Fedora 40

Install MySQL on Fedora 40

In this tutorial, we will show you how to install MySQL on Fedora 40. MySQL is a widely used open-source relational database management system (RDBMS) that plays a crucial role in many web applications and data-driven projects. Known for its reliability, performance, and ease of use, MySQL has become a go-to choice for developers and system administrators alike.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MySQL database on a Fedora 40.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A server running one of the following operating systems: Fedora 40.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
  • A stable internet connection to download the necessary packages.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install MySQL on Fedora 40

Step 1. Update the System.

To ensure a smooth and secure installation, it is crucial to update your Fedora 40 system before proceeding with the Nginx installation. Updating the system ensures that you have the latest security patches, bug fixes, and compatible dependencies. Open your terminal and run the following command:

sudo dnf clean all
sudo dnf update

This command will fetch the latest package information from the Fedora repositories and upgrade any outdated packages to their latest versions. The process may take a few minutes, depending on the number of updates available.

Step 2. Installing MySQL on Fedora 40.

Fedora 40’s default repositories do not include the latest version of MySQL. To install MySQL 8, we need to add the official MySQL repository to our system. Start by downloading the MySQL 8.0 community release RPM package from the MySQL downloads page. Once downloaded, install the RPM package using the following command:

sudo rpm -ivh mysql80-community-release-fc40-1.noarch.rpm

This command will add the MySQL repository to your Fedora 40 system. To verify that the repository has been successfully added, run:

sudo dnf repolist

With the MySQL repository added, we can now proceed to install the MySQL server. Use the following command to install the mysql-community-server package:

sudo dnf install mysql-community-server

This command will also install any required dependencies. Once the installation is complete, start the MySQL service and enable it to run at system startup using the following systemctl commands:

sudo systemctl start mysqld
sudo systemctl enable mysqld

To check the status of the MySQL service, run:

sudo systemctl status mysqld

If the service is running correctly, you will see an “active (running)” status in the output.

Step 3. Secure MySQL Installation.

After installing MySQL, it is crucial to secure the installation to protect your data and prevent unauthorized access. MySQL provides a handy script called mysql_secure_installation that guides you through the process of setting up basic security measures. Run the script with the following command:

sudo mysql_secure_installation

The script will prompt you to set a root password, remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables. It is highly recommended to answer “Y” (yes) to all these prompts to ensure a secure MySQL setup. When prompted, choose a strong root password and remember it for future use.

Step 4. Create a Database and User.

Now that MySQL is installed and secured, let’s create a sample database and a user with the necessary privileges. Connect to the MySQL shell using the root user:

sudo mysql -u root -p

Enter the root password you set during the secure installation process. Once logged in, create a new database using the following command:

CREATE DATABASE sampledb;

Next, create a new user and grant them privileges to access the newly created database:

CREATE USER 'sampleuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON sampledb.* TO 'sampleuser'@'localhost';

Replace ‘sampleuser‘ with your desired username and ‘password’ with a strong password. The GRANT command gives the user full privileges on the sampledb database. After granting privileges, flush them to ensure the changes take effect immediately:

FLUSH PRIVILEGES;

You can now exit the MySQL shell by typing:

EXIT;

Step 5. Uninstall MySQL (Optional).

If you ever need to uninstall MySQL from your Fedora 40 system, you can do so using the following command:

sudo dnf remove mysql-community-server

This command will remove the MySQL server package. To completely remove all MySQL-related packages and dependencies, run:

sudo dnf autoremove

After uninstalling, make sure to remove the MySQL data directory (/var/lib/mysql) if you no longer need the data.

Congratulations! You have successfully installed MySQL. Thanks for using this tutorial for installing the MySQL database on your Fedora 40 system. For additional or useful information, we recommend you check the official MySQL website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button