How to Install MySQL 8.0 on Fedora 39/38/37 Linux

MySQL 8.0 marks a significant milestone in the world of database management systems (DBMS). Released in April 2018, this major version upgrade introduces a host of new features, performance improvements, and architectural changes compared to its predecessor, MySQL 5.7. As a highly popular open-source relational database, MySQL continues to evolve and adapt to the ever-changing needs of developers, administrators, and organizations worldwide.

Some key differences between MySQL 8.0 and previous major releases include:

  • Data Dictionary: MySQL 8.0 introduces a new transactional data dictionary, which stores metadata in InnoDB tables rather than in the traditional .frm files. This allows for a more reliable and efficient management of metadata, reducing the risk of inconsistencies and improving performance.
  • Atomic DDL: Another significant change in MySQL 8.0 is the introduction of atomic Data Definition Language (DDL) statements. This feature enables atomic and crash-safe DDL operations, which help maintain data consistency and minimize the risk of database corruption.
  • Enhanced JSON Support: MySQL 8.0 offers improved JSON functionality, including new JSON functions, optimized storage, and better performance. These enhancements make working with JSON data in MySQL even more efficient and user-friendly.
  • Unicode Support: MySQL 8.0 now provides complete support for Unicode 9.0 and offers improved performance for UTF-8 character sets. This means that the database can natively handle a wider range of characters and languages, making it more accessible for global applications.
  • Common Table Expressions (CTEs) and Window Functions: With MySQL 8.0, developers can leverage Common Table Expressions (CTEs) and Window Functions to write more expressive and efficient queries. These features enable better handling of hierarchical and analytical queries, leading to increased productivity and cleaner code.
  • Improved Security: MySQL 8.0 introduces a number of security enhancements, such as support for OpenSSL as the default TLS/SSL library, enhanced password management, and the ability to define roles for users, which help to protect your data and maintain compliance with industry standards.
  • Optimizer Improvements: The MySQL 8.0 optimizer features significant enhancements, including histograms for better query optimization, improved performance schema, and enhanced execution plans. These improvements allow for faster query execution and better resource utilization.
  • InnoDB Enhancements: The InnoDB storage engine has undergone various improvements in MySQL 8.0, including better support for spatial indexes, full-text search enhancements, and improved performance for read-only workloads.

As you can see, MySQL 8.0 offers a range of new features and enhancements that make it a powerful and versatile choice for database management. The following guide will demonstrate how to install MySQL 8.0 on Fedora Linux using Fedora’s repository or the official MySQL Community repository.

Update Fedora

It is crucial to keep your system up-to-date to prevent potential issues during the installation of MySQL 8.0 and ensure the optimal functionality of your Fedora operating system. To achieve this, execute the following command, which will allow you to check for and install any available updates for your operating system:

sudo dnf upgrade --refresh

Method 1: Install MySQL 8.0 with Fedora Repository

The installation of MySQL 8.0 on Fedora can be done in several ways. One of the methods involves using the Fedora repository to install MySQL 8.0. Fedora updates its packages frequently, making it an excellent distribution for those who desire the latest packages.

To check for the availability of other MySQL versions, execute the following command:

sudo dnf module list mysql

Example output from dnf module MySQL command:

If you are using the default installation of Fedora, MySQL 8.0 is likely to be the only available version, displayed with the [d] flag. To enable MySQL 8.0, execute the following command:

sudo dnf module enable mysql:8.0

Once MySQL 8.0 has been enabled, proceed to install MySQL and MySQL server by running the following command:

sudo dnf install mysql mysql-server

After installing MySQL 8.0 on your Fedora operating system, verifying that the installation was successful before using it is essential. To check the version of MySQL that was installed, run the following command:

mysql --version

Once you have confirmed the installation, it is crucial to activating MySQL 8.0 to ensure it is running correctly. To activate MySQL 8.0, execute the following command:

sudo systemctl enable mysqld --now

This command will start MySQL in your current session and automatically restart it on future system reboots.

Method 2: Install MySQL 8.0 Community Edition

If you require the latest version of MySQL 8.0, install it on your Fedora operating system by following the steps below.

Begin by importing the official RPM for the MySQL 8.0 community edition by using the following command:

To import the MySQL 8.0 Community Edition for Fedora 38, use the following command:

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

To import the MySQL 8.0 Community Edition for Fedora 37, use the following command:

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

To import the MySQL 8.0 Community Edition for Fedora 36, use the following command:

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

After the import, you can verify that the repository was successfully added by using the following command:

dnf repolist all | grep mysql | grep enabled

Example output:

Next, you can install the MySQL 8.0 Community Server using the following command:

sudo dnf install mysql-community-server

Upon completion of the installation, you can confirm the build of the MySQL 8.0 version by running the following command:

mysql --version

Finally, you can activate MySQL 8.0 using the following command:

sudo systemctl enable mysqld --now

This command will start MySQL in your current session and automatically restart it on future system reboots, ensuring it is always available.

MySQL System Commands

After installing MySQL 8.0 on your Fedora system, verifying that the MySQL server is operational is crucial. The installer automatically starts the default MySQL service and configures it to start automatically on system startup. To check the status of the MySQL service, execute the following command:

systemctl status mysqld

Example output:

This command will display the current status of the MySQL service, including any error messages or warnings.

Sometimes, it may be necessary to stop or start the MySQL service manually. To stop the MySQL service, use the following command:

sudo systemctl stop mysqld

Conversely, to start the MySQL service, use the following command:

sudo systemctl start mysqld

If you do not want the MySQL service to start automatically on system startup, you can disable it by using the following command:

sudo systemctl disable mysqld

If you prefer to enable the MySQL service to start automatically on system startup, use the following command:

sudo systemctl enable mysqld

Finally, if you need to restart the MySQL service for any reason, execute the following command:

sudo systemctl restart mysqld

Secure MySQL 8 with a security script

When installing MySQL 8.0 on your Fedora operating system, many security standards may consider the default settings weak, potentially allowing hackers to exploit the system. To address this issue, you can run the installation security script, which provides an additional layer of security to your MySQL installation.

Begin by launching the security script by executing the following command:

sudo mysql_secure_installation

By default, the root password for MySQL should be blank. However, if the password has been set for some reason, you can generate a temporary password to log into the MySQL security script by executing the following command:

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

During the configuration process, the script will guide you through the following steps:

  1. Setting the password for root accounts.
  2. Setting the password for other accounts.
  3. Removal of root accounts accessible from outside the local host.
  4. Removal of anonymous user accounts.
  5. Removal of the test database is accessible by default to anonymous users.

You will be prompted with a series of questions, and you can delete everything by entering “Y” when prompted. If you prefer, you can also reset your root password by creating a new one. Follow the prompts to create a new password, set the root account permissions, remove the test database, and reload the privilege tables.

Here is an example of the output that you can expect when running the script:

[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!

Additional Tips

SELinux Troubleshooting

If you are experiencing issues with SELinux and MySQL or MySQL 8.0 Community Server from MySQL repositories, you may need to adjust some SELinux settings. SELinux is a security mechanism in Linux that can cause problems with MySQL installations. Here are some SELinux commands that may help troubleshoot issues with MySQL:

Check the current status of SELinux:

sestatus

Check the SELinux context of the MySQL data directory and socket file:

ls -lZ /var/lib/mysql
ls -lZ /var/lib/mysql/mysql.sock

If the context of the MySQL data directory and socket file is not correct, you can change it using the following command:

chcon -Rv --type=mysql_db_t /var/lib/mysql
chcon -v --type=mysql_var_run_t /var/lib/mysql/mysql.sock

If SELinux is preventing MySQL from accessing the network, you can run the following command to allow MySQL to communicate over the network:

setsebool -P mysql_connect_any 1

If you are still experiencing issues with SELinux, you can temporarily disable it using the following command:

setenforce 0

Connect to the MySQL 8 Terminal Instance

To connect to the MySQL 8 terminal instance and run common commands, follow these steps:

Open the terminal and enter the following command to connect to the MySQL server as the root user:

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 to list all the available databases on the server:

SHOW DATABASES;

To select the specified database as the default database to use for future commands, use the following command:

USE database_name;

You can run the following command to list all the tables in the current database:

SHOW TABLES;

To get a description of the specified table, including its columns and their data types, use the following command:

DESCRIBE table_name;

To retrieve all the data from the specified table, use the following command:

SELECT * FROM table_name;

To insert data into the specified table, use the following command:

INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);

To update data in the specified table that meets the specified condition, use the following command:

UPDATE table_name SET column_name = value WHERE condition;

To delete data from the specified table that meets the specified condition, use the following command:

DELETE FROM table_name WHERE condition;

You can use these commands to interact with the MySQL databases and manipulate the data stored in them from the command line.

Remove (Uninstall) MySQL 8.0

If you have decided that you no longer need the MySQL database and want to remove it completely, you can do so by running the appropriate command, depending on the version of MySQL that you have installed.

For users with MySQL 8.0 installed from the default Fedora repository, use the following command:

sudo dnf remove mysql

For users with MySQL 8.0 Community Edition installed, use the following command:

sudo dnf remove mysql-community-server

Conclusion: Installing MySQL 8.0 on Fedora Linux

In conclusion, MySQL is a powerful and widely used open-source relational database management system popular among developers and businesses for its scalability, flexibility, and reliability. In this guide, we have demonstrated how to install MySQL 8.0 on Fedora using the command line terminal, either with the default version in Fedora’s repository or by installing the MySQL 8.0 Community Edition.

Share to...