How To Install MariaDB on Fedora 42
MariaDB has become one of the most popular open-source relational database management systems in the Linux ecosystem. As a powerful fork of MySQL, it offers robust performance, enhanced features, and fully open-source licensing that makes it appealing for developers and system administrators working with Fedora. Whether you’re setting up a development environment, deploying a production server, or simply expanding your Linux skills, installing MariaDB on Fedora 42 is a valuable addition to your technical toolkit.
In this comprehensive guide, we’ll explore multiple methods for installing MariaDB on Fedora 42, from the simplest repository-based approach to more advanced techniques. We’ll also cover essential post-installation tasks, configuration options, and troubleshooting tips to ensure your database system runs smoothly.
Understanding MariaDB vs MySQL
Before diving into installation procedures, it’s important to understand what distinguishes MariaDB from MySQL. While both share common roots, they’ve diverged significantly over time.
MariaDB originated as a fork of MySQL when Oracle acquired Sun Microsystems (which owned MySQL). The key difference lies in licensing-MariaDB is fully GPLv2 licensed, providing greater freedom for users and developers. MySQL, on the other hand, offers two licensing options: GPLv2 for the Community edition and a proprietary license for the Enterprise edition.
Feature-wise, MariaDB has implemented several innovations not found in MySQL, including better performance optimizations, additional storage engines, and enhanced security features. Despite these differences, MariaDB maintains high compatibility with MySQL, making migration between the two systems possible, though not always trivial.
Important limitation: You cannot install both MariaDB and MySQL simultaneously on the same Fedora system as their packages conflict by providing similar files. You must choose one database system for your installation.
Preparing Your Fedora 42 System
Before installing MariaDB, it’s essential to prepare your Fedora system properly. This preparation ensures a smooth installation process and helps prevent potential issues down the line.
Update Your System
First, update your Fedora packages to ensure you have the latest security patches and software versions:
sudo dnf upgrade --refresh -y
This command refreshes the package lists and upgrades all installed packages to their latest versions.
Check for Existing Installations
Verify if you already have MySQL or MariaDB installed:
sudo dnf list installed | grep -E 'mysql|mariadb'
If you find existing installations that you want to replace, consider backing up your data before proceeding.
Install Dependencies
Ensure you have the necessary dependencies installed:
sudo dnf install dnf-plugins-core -y
This package provides additional functionality for the DNF package manager and will be helpful during the installation process.
Method 1: Installing MariaDB from Fedora’s Main Repository
The simplest and most straightforward method to install MariaDB on Fedora 42 is using the official Fedora repository. This approach ensures you get a version that’s well-tested and optimized for your distribution.
1. Install the MariaDB Server Package
Execute the following command to install MariaDB server:
sudo dnf install mariadb-server
This command installs the MariaDB server package along with all necessary dependencies.
2. Start the MariaDB Service
Once installation completes, start the MariaDB service:
sudo systemctl start mariadb
3. Enable MariaDB to Start at Boot
To ensure MariaDB starts automatically whenever your system boots:
sudo systemctl enable mariadb
This command configures systemd to launch MariaDB at system startup.
4. Verify Installation Status
Check if MariaDB is running correctly:
sudo systemctl status mariadb
You should see output indicating that the service is active and running. If you encounter any issues, the status output often provides helpful diagnostic information.
Method 2: Installing Specific MariaDB Versions Using Modules
Fedora uses the concept of modules to provide different versions of software packages. This approach is particularly useful when you need a specific version of MariaDB rather than the default one.
1. Check Available MariaDB Module Streams
First, list all available MariaDB module streams:
sudo dnf module list mariadb
This command shows all MariaDB versions available as modules in Fedora repositories.
2. Enable Your Preferred MariaDB Version
For example, to enable MariaDB 10.7:
sudo dnf module enable mariadb:10.7 -y
This command switches the repository to use the specified version stream.
3. Install MariaDB Server from the Enabled Module
sudo dnf install mariadb-server -y
4. Verify the Installed Version
Check which version was installed:
mariadb --version
This command displays the installed MariaDB version and build information.
5. Start and Enable the MariaDB Service
sudo systemctl enable mariadb --now
The --now
option both enables the service for automatic startup and immediately starts it in a single command.
Method 3: Building MariaDB from Source
For advanced users who need cutting-edge features or custom configurations, building MariaDB from source provides maximum flexibility. This method requires more technical knowledge but offers complete control over the installation.
1. Install Build Dependencies
First, install all necessary build tools and dependencies:
sudo dnf groupinstall "Development Tools" -y
sudo dnf builddep mariadb-server -y
These commands install the development toolchain and all dependencies required to build MariaDB.
2. Download Source Code
Obtain the MariaDB source code from the official repository:
git clone https://github.com/MariaDB/server.git mariadb-server
cd mariadb-server
git checkout 10.11 # or your preferred version branch
3. Configure and Build
Run the build configuration:
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb
Compile the source code:
make -j$(nproc)
The -j$(nproc)
option uses all available CPU cores to accelerate the build process.
4. Install the Compiled MariaDB
sudo make install
5. Configure for System Use
Create a dedicated database user:
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
Initialize the database directory:
sudo /usr/local/mariadb/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data
Create a systemd service file for easier management.
Building from source is recommended for users who need specific features, customizations, or the absolute latest version not yet available in Fedora repositories.
Method 4: Installing MariaDB with Containers
Containerization provides an isolated, reproducible environment for running MariaDB without affecting your host system configuration. This method is excellent for development, testing, or when you need multiple database versions.
1. Install Podman if Not Already Present
sudo dnf install podman -y
2. Pull the MariaDB Container Image
podman pull mariadb/server
3. Run a MariaDB Container Instance
podman run -d --name=mariadb -e MYSQL_ROOT_PASSWORD=yourpassword -p 3306:3306 mariadb/server
This command:
- Runs MariaDB in detached mode (
-d
) - Names the container “mariadb”
- Sets a root password
- Maps the container’s port 3306 to your host’s port 3306
4. Connect to the Containerized MariaDB Server
podman exec -it mariadb mysql -uroot -p
This command opens a shell inside the container and connects to the MariaDB server.
5. Optional: Create a Persistent Volume
For data persistence across container restarts:
podman run -d --name=mariadb -e MYSQL_ROOT_PASSWORD=yourpassword -v /path/on/host:/var/lib/mysql -p 3306:3306 mariadb/server
The containerized approach offers excellent isolation and flexibility but may not be ideal for high-performance production environments.
Securing Your MariaDB Installation
After installing MariaDB, securing it should be your top priority. The database server includes a security script that helps implement basic security practices.
1. Run the Security Script
sudo mysql_secure_installation
Or, on newer versions:
sudo mariadb-secure-installation
This interactive script guides you through several security enhancements.
2. Configure Security Options
During the script execution, you’ll answer several questions:
- Set a root password (if not already set)
- Remove anonymous users (recommended: Yes)
- Disallow remote root login (recommended: Yes)
- Remove test database and access (recommended: Yes)
- Reload privilege tables (recommended: Yes)
3. Understanding Authentication Methods
MariaDB on Fedora typically uses Unix socket authentication by default, which means the root user can access MariaDB without a password when connecting via the local socket as the system root user. This enhances security by tying database access to system access controls.
For applications or regular users, password authentication is still commonly used.
4. Additional Security Recommendations
- Create dedicated database users for each application
- Grant minimal necessary privileges
- Use strong passwords
- Consider implementing network-level security (firewalls)
- Regularly update MariaDB to patch security vulnerabilities
Basic MariaDB Configuration
MariaDB’s configuration can be customized to optimize performance and behavior based on your specific needs.
1. Configuration File Locations
The main configuration files for MariaDB on Fedora are:
/etc/my.cnf
– Global configuration file/etc/my.cnf.d/
– Directory containing additional configuration files~/.my.cnf
– User-specific configuration
2. Essential Configuration Parameters
Some important parameters to consider adjusting:
max_connections
– Maximum number of simultaneous client connectionsinnodb_buffer_pool_size
– Memory allocated for data and index cachingkey_buffer_size
– Buffer for MyISAM table indexeslog_error
– Error log file locationcharacter-set-server
– Default character set
3. Applying Configuration Changes
After modifying configuration files, restart MariaDB to apply the changes:
sudo systemctl restart mariadb
4. Monitoring and Log Files
MariaDB generates several log files for monitoring and troubleshooting:
- Error log (default:
/var/log/mariadb/mariadb.log
) - Slow query log
- General query log
- Binary log (for replication)
Regularly review these logs to identify performance issues or potential security concerns.
Creating Databases and Users
Now that your MariaDB server is installed and secured, you’ll want to create databases and user accounts for your applications.
1. Connect to MariaDB as Root
sudo mysql
Or if you’ve set a password:
mysql -u root -p
2. Create a New Database
CREATE DATABASE mydatabase;
3. Create a New User with Appropriate Permissions
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
For more restricted access, specify only the necessary privileges:
GRANT SELECT, INSERT, UPDATE, DELETE ON mydatabase.* TO 'myuser'@'localhost';
4. Apply Privilege Changes
FLUSH PRIVILEGES;
This command ensures that the privilege changes take effect immediately.
5. Verify Access
Exit the MariaDB shell and test the new user’s access:
mysql -u myuser -p mydatabase
Troubleshooting Common Installation Issues
Even with careful planning, you might encounter issues during or after MariaDB installation. Here are solutions to common problems:
Service Startup Failures
If MariaDB fails to start:
sudo systemctl status mariadb
Check the error logs for specific issues:
sudo journalctl -u mariadb
Common causes include:
- Permission problems with data directory
- Port conflicts
- Insufficient memory
- Corrupted tables or logs
Package Conflicts with MySQL
If you see errors about package conflicts:
Error: mysql-community-server conflicts with mariadb-server
You need to remove MySQL packages before installing MariaDB, or vice versa:
sudo dnf remove mysql-community-server mysql-community-client
Authentication Problems
If you can’t log in despite correct credentials:
- Reset the root password:
sudo systemctl stop mariadb sudo mysqld_safe --skip-grant-tables & mysql -u root
- Then within MySQL:
USE mysql; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES; EXIT;
- Finally:
sudo systemctl restart mariadb
Recovering from Upgrade Issues
If upgrading Fedora causes MariaDB database corruption, you might see errors about InnoDB crashes or version incompatibilities. To recover:
- Install an older compatible version if possible
- Recover data using backup
- Clean install the new version and import data
Advanced MariaDB Features on Fedora
Once you have a working MariaDB installation, you might want to explore its advanced features:
MariaDB Galera Cluster
For high availability and scalability, consider MariaDB Galera Cluster:
sudo dnf install mariadb-server-galera
Performance Monitoring Tools
Install monitoring tools for database performance analysis:
sudo dnf install mariadb-server-utils mytop
Backup and Recovery Options
Set up regular backups using tools like:
# Logical backups
mysqldump -u root -p --all-databases > full_backup.sql
# Physical backups with Mariabackup
sudo dnf install mariadb-backup
mariabackup --backup --target-dir=/backup/location --user=root --password=yourpassword
Congratulations! You have successfully installed MariaDB. Thanks for using this tutorial for installing the MariaDB database on your Fedora 42 Linux system. For additional or useful information, we recommend you check the official MariaDB website.