How to Install MySQL 8.0 on Fedora 35

MySQL is a relational database management system based on SQL (Structured Query Language). It is one of the most widely used database software for several well-known applications. MySQL is used for data warehousing, e-commerce, and logging applications, but its more commonly used feature is a web database storage and management.

In the following tutorial, you will learn how to install MySQL 8.0 on Fedora 35 Workstation or Server.

Prerequisites

  • Recommended OS: Fedora Linux 35.
  • User account: A user account with sudo or root access.

Update Operating System

Update your Fedora operating system to make sure all existing packages are up to date:

sudo dnf upgrade --refresh -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@fedora ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Fedora.

To use the root account, use the following command with the root password to log in.

su

Install Dependency Required

Before you proceed with the installation, run the following command to install or check that the package dnf-plugins-core is installed on your Fedora desktop.

sudo dnf install dnf-plugins-core -y

By default, this should be installed.

Option 1. Install MySQL 8.0 using Appstream (Recommended)

By default, MySQL 8.0 Community is available as the default choice in Fedora. It is entirely up to date given that Fedora often shifts the newest packages very quickly, being the distribution focused on the latest packages.

First, check if other versions are available with the following command.

sudo dnf module list mysql

Example output:

How to Install MySQL 8.0 on Fedora 35

Currently, at the time of this tutorial, only MySQL 8.0 is available and is the default displayed with the  [d]  flag.

Luckily you haven’t enabled MySQL 8. Use the following command.

sudo dnf module enable mysql:8.0 -y

Install using the following terminal command.

sudo dnf install mysql mysql-server

Example output:

How to Install MySQL 8.0 on Fedora 35

Type Y, and then press the ENTER KEY to proceed with the installation.

Rerun the install command to start over.

When the installation is complete, verify the installation using the –version command.

mysql --version

Sample output:

mysql  Ver 8.0.27 for Linux on x86_64 (Source distribution)

Then activate MySQL 8 using the following command.

sudo systemctl enable mysqld --now

The above command will start MySQL in your current session and, on future systems, restart automatically.

Option 2. Install MySQL 8.0 Community Edition (Latest)

For those users who need the latest version of MySQL 8.0 or, for that matter, any other version, the following steps below will accomplish this goal. Do note, Fedora’s default version is often the same as this, but when MySQL pushes a new update release, and it is not a security-related release, this can often be a few weeks behind; however, for most, this isn’t a problem.

Note that the difference between AppStream and the latest version of MySQL RPM is minor at the time of this tutorial.

First, use the following command to import the official RPM of the MySQL 8.0 community.

sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-fc35-1.noarch.rpm

Then verify that the repository was added successfully by printing it from the dnf repolist.

dnf repolist all | grep mysql | grep enabled

Example output:

How to Install MySQL 8.0 on Fedora 35

Then install MySQL 8 Community Server. The following command will disable the App Stream version and enable the community edition.

sudo dnf install mysql-community-server

Example output:

How to Install MySQL 8.0 on Fedora 35

Type Y,  and then press the  ENTER KEY  to proceed with the installation.

Please note, you will be asked to import GPG keys, TYPE Y, to complete the installation.

Example:

How to Install MySQL 8.0 on Fedora 35

Then confirm the build of the version, which will also verify the success of the installation.

mysql --version

Example output:

mysql  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

Then activate MySQL 8 using the following command.

sudo systemctl enable mysqld --now

The above command will start MySQL in your current session and, on future systems, restart automatically.

Check the Status of the MySQL 8 Server

The installer will automatically start your default MySQL service and configure itself to start automatically on system startup. To verify that your MySQL service is operational after installation, type the following  systemctl command :

systemctl status mysqld

Example output:

How to Install MySQL 8.0 on Fedora 35

To stop the MySQL service:

sudo systemctl stop mysqld

To start the MySQL service:

sudo systemctl start mysqld

To disable the MySQL service at system startup:

sudo systemctl disable mysqld

To activate the MySQL service at system startup:

sudo systemctl enable mysqld

To restart the MySQL service:

sudo systemctl restart mysqld

Secure MySQL 8 with a security script

When installing MySQL, the new defaults are considered weak by most standards and raise concerns about the potential of allowing intrusion or exploitation by hackers. One solution is to run the installation security script with the MySQL installation.

First, use the following command to launch the  (mysql_secure_installation) :

sudo mysql_secure_installation

By default, the root password should be blank. If the password has been set for some reason, use the following command to generate a temporary password to log into the MySQL Security script. During configuration, you will set a new password.

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

Example:

How to Install MySQL 8.0 on Fedora 35

You will be prompted for your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this involves defining password complexity checks; for the most part, the default is correct.

Then follow below:

  • Setting the password for root accounts.
  • Setting the password for the accounts.
  • Removal of root accounts accessible from outside the local host.
  • Removal of anonymous user accounts.
  • Removal of the test database, accessible by default to anonymous users.

Be careful; you use (Y) to delete everything. In addition, if you wish, you can reset your root password by creating a new one; you can ignore it if you want, as you already set it during the initial installation with the pop-ups.

Example:

[joshua@fedora ~]$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: <---- SET NEW PASSWORD

Re-enter new password: <---- RE-ENTER NEW PASSWORD

Re-enter new password: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY (SKIP IF YOU ALREADY JUST SET)

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
Success.

All done!

Connect to the MySQL 8 Terminal Instance

Now that you have completed the installation security script, connecting to your MySQL database can be done using the following:

sudo mysql -u root -p

You will be prompted to enter the root password you defined in the installation configuration or the post-installation security script. Once inside the MySQL service instance, you can run the following command as a test to see it work.

Type the following text  (DISPLAY DATABASE command) :

SHOW DATABASES;

For those new to MySQL, all commands must end with ; 

Example:

How to Install MySQL 8.0 on Fedora 35

TO (CREATE) a database, use the following command.

CREATE DATABASE MYDATA;

To delete (DROP) a database, use the following command.

DROP DATABASE MYDATA;

To exit the terminal, type the following  exit command :

EXIT;

How to Remove (Uninstall) MySQL 8.0

If you no longer want to use the MySQL database and want to delete it entirely, run the following command:

sudo dnf remove mysql

Use the following command for users with MySQL 8.0, Community Edition installed.

sudo dnf remove mysql-community-server

Comments and Conclusion

In the tutorial, you learned how to install the latest version of MySQL 8 on Fedora 35. Additionally, as well as optimization options for specific workloads on specific hardware by mapping user threads to processors, just a few of the new features.

Overall, MySQL 8 provides better performance for read/write workloads, I/O-related workloads, and high contention workloads. Users of older versions of MySQL should consider upgrading, as the performance gains are well worth it.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!