FedoraRHEL Based

How To Install MySQL on Fedora 42

Install MySQL on Fedora 42

MySQL is one of the most popular open-source relational database management systems available today. As organizations and developers rely heavily on robust database solutions, knowing how to properly install and configure MySQL on your Fedora 42 Linux distribution is an essential skill. Whether you’re setting up a development environment or preparing a production server, this comprehensive guide will walk you through the entire process of installing MySQL 8.0.42 on the latest Fedora release.

Introduction

MySQL has established itself as a cornerstone technology in web development, data management, and enterprise applications. Its reliability, performance, and extensive feature set make it the database of choice for countless applications worldwide. Fedora 42, the latest version of this cutting-edge Linux distribution, offers excellent compatibility with MySQL 8.0.42, providing a stable platform for database operations.

In this guide, we’ll explore three distinct methods to install MySQL on your Fedora 42 system:

  1. Installation from the official MySQL repository
  2. Installation using Fedora’s main repository
  3. Containerized installation using Podman

Each approach has its advantages and specific use cases. By the end of this article, you’ll have a fully functional MySQL installation tailored to your specific requirements, along with the knowledge to secure and optimize your database environment.

Prerequisites

Before diving into the MySQL installation process, ensure your Fedora 42 system meets the following requirements:

System Requirements

To run MySQL 8.0.42 efficiently on Fedora 42, your system should have:

  • At least 2GB RAM (4GB or more recommended for production environments)
  • Minimum 10GB available disk space (MySQL installation itself requires approximately 830MB)
  • A stable internet connection for downloading packages
  • Administrative (sudo) privileges

Pre-Installation Checks

Before proceeding with installation, perform these important checks:

  1. Update your system: Ensure your Fedora 42 installation is up-to-date by running:
    sudo dnf update
  2. Check for existing MySQL installations: MySQL conflicts with MariaDB (a MySQL fork), so verify if either is already installed:
    sudo dnf list installed | grep -E 'mysql|mariadb'
  3. Backup existing data: If you’re upgrading from a previous MySQL version or migrating from MariaDB, back up your databases:
    sudo mysqldump --all-databases > mysql_backup.sql

With these prerequisites in place, you’re ready to install MySQL on your Fedora 42 system using your preferred method.

Method 1: Installing MySQL from Official MySQL Repository

The official MySQL repository provides the most up-to-date and feature-complete version of MySQL directly from Oracle. This method ensures you get the exact version (8.0.42) with all official features and timely updates.

Downloading the MySQL Repository Package

  1. Open your web browser and navigate to the official MySQL website (mysql.com)
  2. Click on “Downloads” and select “MySQL Community Downloads”
  3. Choose “MySQL Community Server”
  4. Select version 8.0.42 from the dropdown menu
  5. Select “Fedora” as the operating system and “Fedora 42” as the version
  6. Download the RPM bundle package (approximately 829MB)

Alternatively, you can download it directly using the terminal:

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.42-fedora42-x86_64.tar.gz

Adding the MySQL Yum Repository

Once the download completes, follow these steps to extract and install the repository package:

  1. Navigate to your Downloads directory:
    cd Downloads
  2. Extract the RPM bundle:
    tar -xf mysql-8.0.42-fedora42-linux-x86_64-bundle.tar
  3. Install the repository package:
    sudo rpm -ih mysql80-community-release-fc42-1.noarch.rpm
  4. If you encounter conflicts with MariaDB packages, remove them first:
    sudo dnf remove mariadb-connector-c
  5. Verify the repository installation:
    sudo dnf repolist | grep mysql

Installing MySQL Server 8.0.42

With the repository configured, proceed with the MySQL server installation:

  1. Install MySQL server:
    sudo dnf install mysql-community-server
  2. During installation, the system will download and install all necessary dependencies. This might take several minutes depending on your internet connection speed.
  3. Once installation completes, verify it by checking the installed packages:
    dnf list installed | grep mysql

Starting and Enabling MySQL Service

After successful installation, start the MySQL service:

  1. Start the MySQL service:
    sudo systemctl start mysqld
  2. Enable MySQL to start automatically at system boot:
    sudo systemctl enable mysqld
  3. Verify the MySQL service is running:
    sudo systemctl status mysqld

    Look for “active (running)” in the output, confirming that MySQL is operating correctly.

Securing the MySQL Installation

For security reasons, MySQL generates a temporary root password during installation. Follow these steps to secure your installation:

  1. Retrieve the temporary root password:
    sudo grep 'temporary password' /var/log/mysqld.log
  2. Launch the MySQL secure installation utility:
    sudo mysql_secure_installation
  3. When prompted, enter the temporary password
  4. Set a new strong root password (must include uppercase, lowercase, digits, and special characters)
  5. Answer the security questions:
    • Change the root password? (Only if needed)
    • Remove anonymous users? (Recommended: Y)
    • Disallow root login remotely? (Recommended: Y)
    • Remove test database and access to it? (Recommended: Y)
    • Reload privilege tables? (Recommended: Y)

After completing these steps, your MySQL installation is secured against common vulnerabilities and ready for use.

Method 2: Installing MySQL from Fedora Main Repository

Fedora’s main repository provides a community-maintained version of MySQL that integrates well with the distribution’s package management system. This method offers simplicity and consistency with Fedora’s ecosystem.

Understanding Repository Options

The Fedora repository offers MySQL 8.0 community edition as both a regular package and as a module. This approach has several considerations:

  • Fedora maintains and tests these packages specifically for compatibility with the distribution
  • Updates align with Fedora’s release cycle rather than MySQL’s
  • The community edition is fully GPLv2 licensed
  • Package integration with other Fedora software is seamless

Installation Process

Installing MySQL from Fedora’s repository is straightforward:

  1. Install MySQL server:
    sudo dnf install community-mysql-server
  2. The system will download and install MySQL along with dependencies
  3. The installation is typically faster than using the official repository since package sizes are smaller and optimized for Fedora

Version Management

When using Fedora’s repository, managing MySQL versions follows standard Fedora package practices:

  1. Check the installed MySQL version:
    mysql --version
  2. To view available MySQL module streams:
    sudo dnf module list mysql
  3. Switch to a specific stream if needed:
    sudo dnf module enable mysql:8.0

This approach simplifies version management within the Fedora ecosystem, though you might not always have immediate access to the latest MySQL releases.

Service Configuration

Configure the MySQL service to start and run automatically:

  1. Start the MySQL service:
    sudo systemctl start mysqld
  2. Enable automatic startup:
    sudo systemctl enable mysqld
  3. Verify service status:
    sudo systemctl status mysqld

The service configuration is identical to the official repository method, ensuring consistency in operation.

Security Setup

Securing your MySQL installation follows the same process as with the official repository:

  1. Run the secure installation utility:
    sudo mysql_secure_installation
  2. Set a strong root password and answer security questions
  3. Fedora’s MySQL package includes sensible security defaults but completing this process adds important additional protections

Limitations and Considerations

When using Fedora’s repository, consider these factors:

  • Version availability might lag behind official releases
  • Some enterprise features may be excluded from the community edition
  • Package maintenance follows Fedora’s schedule rather than MySQL’s
  • Integration with other Fedora packages is more seamless
  • Updates come through Fedora’s standard update process

Method 3: Installing MySQL using Podman (Container)

Containerization offers a flexible, isolated approach to running MySQL. Using Podman, Fedora’s native container engine, you can deploy MySQL in a container environment with minimal impact on your host system.

Container Benefits

Containerized MySQL installations provide several advantages:

  • Complete isolation from the host system
  • Easy version management and switching between versions
  • Simplified backup and migration processes
  • Consistent environment across different systems
  • Reduced dependency conflicts with other software

Pulling MySQL Container Image

To begin using containerized MySQL:

  1. Install Podman if not already present:
    sudo dnf install podman
  2. Pull the official MySQL container image:
    podman pull mysql/mysql-server:8.0.42
  3. Verify the image download:
    podman images

The container image includes everything needed to run MySQL in an isolated environment.

Container Creation and Configuration

Create and run a MySQL container with proper configuration:

  1. Run the MySQL container:
    podman run -d --name=mysql -e MYSQL_ROOT_PASSWORD=YourStrongPassword mysql/mysql-server:8.0.42
  2. Verify the container is running:
    podman ps
  3. The `-d` option runs the container in the background (detached mode)

Environment Configuration

Configure the MySQL container environment for optimal operation:

  1. To persistently store MySQL data, add a volume mount:
    podman run -d --name=mysql -e MYSQL_ROOT_PASSWORD=YourStrongPassword -v /path/on/host:/var/lib/mysql mysql/mysql-server:8.0.42
  2. Set additional MySQL environment variables:
    podman run -d --name=mysql \
    -e MYSQL_ROOT_PASSWORD=YourStrongPassword \
    -e MYSQL_DATABASE=mydb \
    -e MYSQL_USER=myuser \
    -e MYSQL_PASSWORD=mypassword \
    -v mysql-data:/var/lib/mysql \
    mysql/mysql-server:8.0.42
  3. Map the MySQL port to make it accessible from the host:
    podman run -d --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=YourStrongPassword mysql/mysql-server:8.0.42

These configurations allow for flexible deployment while maintaining data persistence and accessibility.

Connecting to Containerized MySQL

To connect to MySQL running in a container:

  1. Connect from within the container:
    podman exec -it mysql mysql -uroot -p
  2. Connect from the host system:
    mysql -h 127.0.0.1 -P 3306 -u root -p
  3. If you need to reset the root password:
    podman exec -it mysql mysql -uroot -p
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

The containerized approach provides flexibility while maintaining isolation from your host system.

Post-Installation Configuration

After successfully installing MySQL, proper configuration ensures optimal performance, security, and reliability for your database operations.

MySQL Server Settings

Fine-tune your MySQL server by editing its configuration file:

  1. Locate the configuration file:
    sudo find / -name my.cnf

    Typically found at /etc/my.cnf or /etc/mysql/my.cnf

  2. Create or edit the configuration file:
    sudo nano /etc/my.cnf
  3. Add or modify key settings based on your server resources:
    [mysqld]
    # Memory and Cache Settings
    innodb_buffer_pool_size = 1G  # Adjust to 70-80% of available RAM
    innodb_log_file_size = 256M
    innodb_log_buffer_size = 64M
    
    # Performance Settings
    innodb_flush_log_at_trx_commit = 2
    innodb_file_per_table = 1
    
    # Connection Settings
    max_connections = 150
    
    # Character Set
    character-set-server = utf8mb4
    collation-server = utf8mb4_unicode_ci
  4. Save the file and restart MySQL:
    sudo systemctl restart mysqld

These settings provide a solid foundation for most deployments, but should be adjusted based on your specific workload and available resources.

User and Database Management

Set up proper user accounts and databases for your applications:

  1. Connect to MySQL as root:
    mysql -u root -p
  2. Create a new database:
    CREATE DATABASE myapplication;
  3. Create a dedicated user with appropriate permissions:
    CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongPassword';
    GRANT ALL PRIVILEGES ON myapplication.* TO 'appuser'@'localhost';
    FLUSH PRIVILEGES;
  4. For remote access, create a user with specific host access:
    CREATE USER 'remoteuser'@'192.168.1.%' IDENTIFIED BY 'StrongPassword';
    GRANT SELECT, INSERT, UPDATE, DELETE ON myapplication.* TO 'remoteuser'@'192.168.1.%';
    FLUSH PRIVILEGES;

This approach follows the principle of least privilege, granting users only the permissions they need for their specific tasks.

Network Configuration

Configure MySQL for secure network access:

  1. Edit the MySQL configuration file to allow remote connections:
    sudo nano /etc/my.cnf

    Add or modify:

    [mysqld]
    bind-address = 0.0.0.0  # Listen on all interfaces
  2. Configure the firewall to allow MySQL connections:
    sudo firewall-cmd --permanent --add-service=mysql
    sudo firewall-cmd --reload
  3. For more restricted access, specify allowed IP addresses:
    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" service name="mysql" accept'
    sudo firewall-cmd --reload
  4. If using SELinux, ensure proper context for MySQL:
    sudo setsebool -P mysqld_connect_any 1

These steps ensure your MySQL server is accessible to authorized clients while maintaining security protections.

Testing Your MySQL Installation

Verify your MySQL installation works correctly through comprehensive testing.

Basic Connectivity Testing

Confirm you can connect to the MySQL server:

  1. Connect using the command-line client:
    mysql -u root -p
  2. If successful, you’ll see the MySQL prompt:
    mysql>
  3. Check the MySQL version:
    mysql> SELECT VERSION();

    This should display version 8.0.42

Database Operations

Test basic database operations:

  1. Create a test database:
    mysql> CREATE DATABASE testdb;
  2. Create a test table:
    mysql> USE testdb;
    mysql> CREATE TABLE employees (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(100),
        email VARCHAR(100)
    );
  3. Insert test data:
    mysql> INSERT INTO employees (name, email) VALUES 
        ('John Doe', 'john@example.com'),
        ('Jane Smith', 'jane@example.com');
  4. Query the data:
    mysql> SELECT * FROM employees;

Successful execution of these operations confirms your MySQL installation is functioning correctly.

MySQL Status Verification

Check the MySQL server status and configuration:

  1. View the server status:
    mysql> SHOW STATUS;
  2. Check global variables:
    mysql> SHOW VARIABLES;
  3. View running processes:
    mysql> SHOW PROCESSLIST;
  4. Check installed plugins:
    mysql> SHOW PLUGINS;

These commands provide insights into your MySQL server’s operational status and configuration.

Troubleshooting Common Issues

Even with careful installation, you might encounter issues. Here are solutions to common problems.

Authentication Problems

If you experience authentication issues:

  1. Reset the root password if forgotten:
    sudo systemctl stop mysqld
    sudo mysqld_safe --skip-grant-tables &
    mysql -u root
    mysql> FLUSH PRIVILEGES;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
    mysql> EXIT;
    sudo killall mysqld
    sudo systemctl start mysqld
  2. If encountering plugin compatibility issues:
    mysql> ALTER USER 'username'@'host' IDENTIFIED WITH mysql_native_password BY 'password';

These steps address the most common authentication challenges.

Service Startup Failures

If MySQL fails to start:

  1. Check the error log:
    sudo tail -f /var/log/mysqld.log
  2. Verify permissions on data directory:
    sudo ls -la /var/lib/mysql
    sudo chown -R mysql:mysql /var/lib/mysql
  3. Ensure sufficient disk space:
    df -h
  4. Check for port conflicts:
    sudo netstat -tulpn | grep 3306

Addressing these common causes often resolves startup issues.

Connection Refusal Issues

If clients cannot connect to MySQL:

  1. Verify MySQL is running:
    sudo systemctl status mysqld
  2. Check firewall settings:
    sudo firewall-cmd --list-all
  3. Ensure MySQL is configured to listen on appropriate interfaces:
    grep bind-address /etc/my.cnf
  4. Verify hostname resolution:
    ping database-hostname

These checks identify and help resolve connectivity problems.

Password Reset Procedures

If you need to reset the MySQL root password:

  1. Stop the MySQL service:
    sudo systemctl stop mysqld
  2. Start MySQL in safe mode:
    sudo mysqld_safe --skip-grant-tables &
  3. Connect without a password:
    mysql -u root
  4. Reset the password:
    mysql> FLUSH PRIVILEGES;
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
  5. Stop and restart MySQL normally:
    sudo killall mysqld
    sudo systemctl start mysqld

This procedure provides a reliable way to recover from lost root passwords.

Best Practices for MySQL on Fedora 42

Implement these best practices to maintain a secure, reliable, and performant MySQL installation.

Security Recommendations

Enhance your MySQL security posture:

  1. Use strong, unique passwords for all accounts
  2. Implement regular password rotation
  3. Limit user privileges using role-based access control
  4. Enable MySQL audit logging:
    [mysqld]
    audit_log=FORCE_PLUS_PERMANENT
    audit_log_file=/var/log/mysql/audit.log
  5. Regular security patching:
    sudo dnf update mysql-server

These practices significantly reduce security risks to your database environment.

Backup Strategies

Implement robust backup procedures:

  1. Create regular automated backups:
    mysqldump --all-databases --user=root --password --master-data > database_backup.sql
  2. Configure binary logging for point-in-time recovery:
    [mysqld]
    log-bin=mysql-bin
    binlog_format=ROW
    expire_logs_days=14
  3. Verify backup integrity regularly:
    mysqlcheck --all-databases --check --user=root --password
  4. Store backups in multiple locations, including off-site

A comprehensive backup strategy ensures business continuity even in disaster scenarios.

Performance Optimization

Optimize MySQL performance for your workload:

  1. Use the InnoDB storage engine for all tables
  2. Configure buffer pool size appropriately:
    innodb_buffer_pool_size = 1G  # Adjust based on available RAM
  3. Enable the slow query log to identify performance bottlenecks:
    slow_query_log = 1
    slow_query_log_file = /var/log/mysql/slow-query.log
    long_query_time = 2
  4. Use the MySQL Performance Schema to monitor resource usage:
    performance_schema = ON

These optimizations ensure your MySQL server delivers maximum performance for your specific workloads.

Congratulations! You have successfully installed MySQL. Thanks for using this tutorial for installing the MySQL database on your Fedora 42 Linux 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button