How to set up MariaDB on Linux

Galaxy Glossary

How do I install and secure MariaDB on Linux?

Install, configure, and secure MariaDB on popular Linux distributions.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What packages do I need before installing MariaDB?

Update the package index and install gnupg, software-properties-common, and wget. These tools let you add MariaDB’s official repository and verify packages.

How do I add the MariaDB repository on Ubuntu/Debian?

Run sudo mariadb-keyring install to import GPG keys, then add the repo with sudo add-apt-repository 'deb [arch=amd64] https://mirror.mariadb.org/repo/10.11/ubuntu $(lsb_release -cs) main'. Finally, update with sudo apt update.

How do I install MariaDB on CentOS/RHEL/Fedora?

Enable the official YUM repo with sudo tee /etc/yum.repos.d/MariaDB.repo (use MariaDB’s provided repo file). Then run sudo yum install mariadb-server mariadb or sudo dnf install mariadb-server mariadb.

What is the exact installation and start-up process?

After installing, enable the service: sudo systemctl enable mariadb. Start it with sudo systemctl start mariadb. Check status using sudo systemctl status mariadb.

How do I secure the fresh MariaDB instance?

Execute sudo mysql_secure_installation. Set a strong root password, remove anonymous users, disallow remote root logins, remove the test database, and reload privilege tables.

How do I create an e-commerce database and user?

Log in with sudo mysql -u root -p and run:
CREATE DATABASE ecommerce; CREATE USER 'shop_admin'@'localhost' IDENTIFIED BY 'S3cur3!'; GRANT ALL ON ecommerce.* TO 'shop_admin'@'localhost'; FLUSH PRIVILEGES;

How can I test the installation quickly?

Connect as shop_admin: mysql -u shop_admin -p ecommerce. Create a sample table and insert a row to confirm reads/writes work.

Best practices for production setups?

Configure backups with mysqldump or mariabackup, tune /etc/mysql/mariadb.conf.d/50-server.cnf for innodb_buffer_pool_size, enable the firewall for port 3306 only to trusted hosts, and monitor with mariadb-exporter.

Why How to set up MariaDB on Linux is important

How to set up MariaDB on Linux Example Usage


-- Connect as shop_admin
going$ mysql -u shop_admin -p ecommerce

-- Build tables resembling an online shop
CREATE TABLE Customers (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100),
  email VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Products (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(150),
  price DECIMAL(10,2),
  stock INT
);

INSERT INTO Products (name, price, stock) VALUES ('Noise-Cancelling Headphones', 149.99, 250);

SELECT * FROM Products;

How to set up MariaDB on Linux Syntax


# Ubuntu / Debian
sudo apt update && sudo apt install gnupg wget software-properties-common -y
sudo mariadb-keyring install
sudo add-apt-repository "deb [arch=amd64] https://mirror.mariadb.org/repo/10.11/ubuntu $(lsb_release -cs) main"
sudo apt update && sudo apt install mariadb-server -y

# RHEL / CentOS / Fedora
echo "[mariadb]\nname=MariaDB\nbaseurl=https://downloads.mariadb.com/MariaDB/mariadb-10.11/yum/rhel/$releasever/$basearch\ngpgkey=https://downloads.mariadb.com/MariaDB/mariadb-10.11/yum/rhel/$releasever/$basearch/rpms/MD5SUMS\ngpgcheck=1" | sudo tee /etc/yum.repos.d/MariaDB.repo
sudo yum install mariadb-server mariadb -y

# Universal post-install
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

Common Mistakes

Frequently Asked Questions (FAQs)

Does MariaDB replace MySQL automatically?

No. Both can coexist if listening on different sockets and ports, but package managers may remove MySQL client binaries. Plan migrations carefully.

Which port does MariaDB use by default?

Port 3306/TCP, the same as MySQL. Use firewalls or bind-address to restrict exposure.

How do I uninstall MariaDB completely?

Stop the service, remove packages via apt/yum/dnf, delete /var/lib/mysql, and remove configuration under /etc/mysql or /etc/my.cnf.d.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.