安装 MySQL/MariaDB

Alessio, Héctor Louzao, Ankur Sinha, Michal Schorm Version F43 Last review: 2026-03-25
MySQL is a widely used relational database management system (RDBMS). MariaDB is a community-developed fork of MySQL and is the preferred MySQL implementation in Fedora. While the two products share common origins, they have diverged over time and migrating data between them may not be trivial.

MariaDB is licensed under GPLv2. MySQL uses dual licensing: GPLv2 for the Community Edition and a proprietary license for Enterprise.

Fedora ships versioned packages for both:

  • MariaDB LTS releases, e.g. mariadb10.11, mariadb11.8

  • MySQL LTS releases, e.g. mysql8.4

One version of each in every Fedora release is set as the "distribution default", providing unversioned package names (mariadb, mariadb-server or mysql, mysql-server).

To see which versions are available in your Fedora release:

dnf search mariadb | grep server
dnf search mysql | grep server
Available versions may differ between Fedora releases. MariaDB and MySQL packages conflict because they provide similar files — you can only install one of them at a time.

Install from Fedora repositories

Installing MariaDB

To install the distribution default version:

sudo dnf install mariadb-server

To install a specific version:

sudo dnf install mariadb11.8-server

Installing MySQL

To install the distribution default version:

sudo dnf install mysql-server

To install a specific version:

sudo dnf install mysql8.4-server

Starting the service

For MariaDB:

sudo systemctl enable --now mariadb

For MySQL:

sudo systemctl enable --now mysqld

Connecting

For MariaDB, the root user connects via unix socket authentication without a password:

mysql -u root

For MySQL, you may need to connect with a password:

mysql -u root -p

Removing

sudo dnf remove mariadb-server

or:

sudo dnf remove mysql-server

Install from Oracle MySQL repository

本页讨论非 Fedora 项目官方附属或认可的第三方软件源。请自行决定是否使用它们。Fedora 推荐您使用免费和开源软件,同时建议您避免使用受专利保护的软件。

Oracle provides their own MySQL repository for Fedora. This is useful if you need a version not available in Fedora repositories.

Adding the Oracle MySQL repository

Download the release package from https://dev.mysql.com/downloads/repo/yum/ and install it:

sudo dnf install <path-to-downloaded-rpm>
This repository is maintained by Oracle. Report issues via https://www.mysql.com/about/faq/

Installing and starting MySQL

sudo dnf install mysql-community-server
sudo systemctl enable --now mysqld

MySQL generates a temporary root password on first start. Find it with:

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

Then secure the installation:

sudo mysql_secure_installation

Answer the security questions as you prefer. Use a strong password for the MySQL root user — this is separate from your system root password.

Connecting

mysql -u root -p

Removing Oracle MySQL

sudo dnf remove mysql-community-server mysql-community-libs mysql-community-common

Install using containers

Fedora provides container images on quay.io.

MariaDB container

podman pull quay.io/fedora/mariadb-118
podman run -d --name mariadb -e MYSQL_ROOT_PASSWORD=mypassword quay.io/fedora/mariadb-118

MySQL container

podman pull quay.io/fedora/mysql-84
podman run -d --name mysql -e MYSQL_ROOT_PASSWORD=mypassword quay.io/fedora/mysql-84

Connecting to the database from the container

podman exec -it mariadb mysql -uroot -p

or for MySQL:

podman exec -it mysql mysql -uroot -p

Managing containers

podman start <container-name>
podman stop <container-name>
podman restart <container-name>
podman rm <container-name>

For available images, see https://quay.io/organization/fedora

Using the database

Connect to the database shell:

mysql -u root -p
For MariaDB installed from Fedora repositories, the root user connects via unix socket authentication without a password: mysql -u root

Check the running version:

SELECT version();

Create a database and user:

CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

List available databases:

SHOW DATABASES;

Data location

The database files are stored in /var/lib/mysql.

Allowing remote access

Open the firewall port

sudo firewall-cmd --permanent --zone=public --add-service=mysql
sudo firewall-cmd --reload

or using the port number directly:

sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload

Configure bind address

Edit the configuration to allow connections from other hosts.

Configuration file locations:

  • MariaDB: /etc/my.cnf and /etc/my.cnf.d/

  • MySQL: /etc/my.cnf and /etc/my.cnf.d/

You can find the configuration files for any package with rpm -qc <package-name>.

Set the bind address to accept connections from all interfaces:

[mysqld]
bind-address = 0.0.0.0

Then restart the service:

sudo systemctl restart mariadb

or for MySQL:

sudo systemctl restart mysqld

Create a remote user

CREATE USER 'myuser'@'%' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%';
FLUSH PRIVILEGES;
Replace % with a specific IP address or subnet (e.g. 192.168.1.%) to restrict access to specific hosts.

Connect remotely

mysql -u myuser -h <server-ip> -p

Troubleshooting

Check installed version

dnf list installed | grep -i -e maria -e mysql

Check active configuration

For MariaDB:

mariadbd --print-defaults

For MySQL:

mysqld --print-defaults

Error logs

If the service fails to start, check the journal:

journalctl -xe -u mariadb

or for MySQL:

journalctl -xe -u mysqld

Log files may also be found at:

  • MariaDB: /var/log/mariadb/mariadb.log

  • MySQL: /var/log/mysql/mysqld.log

Socket errors

If you see an error like:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

This usually means the service is not running. Try starting it:

sudo systemctl start mariadb

If the service is running but the socket file is missing, check the configured socket path:

mysql --help | grep socket

Verify the socket file exists:

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

If the file does not exist, ensure the data directory has correct ownership and permissions:

sudo chown mysql:mysql /var/lib/mysql
sudo chmod 755 /var/lib/mysql

Then restart the service:

sudo systemctl restart mariadb

If the problem persists, review the error logs for more details.