
Installing MariaDB on Ubuntu 26.04 is a straightforward job when you know the right order. The real challenge is not the install itself, but making sure the database starts correctly, stays secure, and is ready for real use. In this guide, I will show you how to Install MariaDB on Ubuntu 26.04 with a clean Linux server workflow, the same way a senior sysadmin would set it up on a production box.
MariaDB is a drop-in database server for many Linux applications, and Ubuntu makes it easy to install from the default APT repositories. That said, a safe setup needs more than apt install, because you still need to secure the root account, confirm the service is enabled, and create a proper application user. This article follows a practical How To Install MariaDB on Ubuntu 26.04 approach that is beginner friendly but still solid enough for developers and sysadmins.
You will learn how to install the package, start the service, lock down the default setup, and verify that everything works. I will also cover a basic configure MariaDB on Ubuntu 26.04 workflow, plus common errors you may hit after installation. Each step includes what the command does and why it matters, so you can reuse the logic later on other Linux servers too.
Prerequisites
Before you begin, make sure you have:
- Ubuntu 26.04 LTS installed and updated.
- A user account with sudo privileges.
- A terminal session with internet access.
- At least basic comfort with Linux commands.
- Enough free disk space for MariaDB and your data files.
These requirements matter because MariaDB depends on system packages, service management, and filesystem access. If your user cannot run sudo, you will get blocked at the first install step. If the system is not updated, package metadata can be stale and cause avoidable install errors.
Step 1: Update Your System
Refresh package lists
Run this first:
sudo apt update
This command refreshes Ubuntu’s package index. It tells your system which package versions are currently available in the repositories, so apt can install the right MariaDB package.
Why this step matters
APT uses a local cache of repository data. If that cache is old, Ubuntu may not see the newest package list or security fixes. Updating first lowers the chance of dependency issues and helps the install complete cleanly.
Optional full upgrade
If this is a fresh server and you want to update everything before adding MariaDB, use:
sudo apt upgrade -y
This upgrades already installed packages. It is a good habit on a server because it reduces the chance of old libraries causing trouble during database setup.
Step 2: Install MariaDB on Ubuntu 26.04 setup
Install the server and client packages
Use this command:
sudo apt install mariadb-server mariadb-client -y
The server package gives you the database engine. The client package adds the command-line tools you will use later for login, testing, and database administration.
Why install both packages
A lot of people install only the server and then wonder why the admin tools are missing. The client package gives you mariadb, mariadb-dump, and other useful utilities that make daily work easier. In a real Linux server tutorial, installing both at the start saves time later.
Check the installed version
After installation, verify the version:
mariadb --version
Expected output looks similar to this:
mariadb Ver 15.1 Distrib 11.x.x-MariaDB
The exact version number may vary, but you should see MariaDB 11.x on Ubuntu 26.04. That confirms the package installed correctly and the binary is available in your path.
Step 3: Start and enable the service
Start MariaDB now
Run:
sudo systemctl start mariadb
This starts the database service immediately. It loads MariaDB into memory and makes it ready for local connections.
Enable MariaDB at boot
Run:
sudo systemctl enable mariadb
This tells systemd to start MariaDB automatically every time the server boots. That matters on production systems because a reboot should not leave your database offline.
Confirm service status
Check that the service is running:
sudo systemctl status mariadb
You want to see active (running) in the output. That line tells you the service started cleanly and is currently available.
Why this step matters
A service can run once and still fail after reboot if it is not enabled. That is a common mistake on Linux servers, especially when people install software and move on too quickly. Verifying status now helps you catch issues before they affect an application.
Step 4: Secure the default installation
Run the security script
Now lock down the fresh install:
sudo mariadb-secure-installation
This script improves the default security of MariaDB by setting a root password, removing anonymous users, removing the test database, and disabling remote root access. The manual page confirms those are the main protections it applies.
Answer the prompts carefully
A typical secure setup looks like this:
- Set or change the root password: Yes
- Remove anonymous users: Yes
- Disallow root login remotely: Yes
- Remove test database: Yes
- Reload privilege tables: Yes
Some setups may ask about unix socket authentication. For a local server, socket auth can be convenient, but for many admins a password-based root login is easier to explain and manage consistently. Use the mode that matches your server policy.
Why this step matters
A brand-new MariaDB install is usable, but it is not fully hardened. Anonymous accounts and the test database are not acceptable on a real server. Running the security script closes those gaps in one pass and is one of the most important things you can do after installation.
Restart MariaDB after hardening
sudo systemctl restart mariadb
This reloads the service so the security changes take effect. If you skip the restart, some settings may not apply right away.
Step 5: Log in and verify access
Connect as root
Use this command:
sudo mariadb -u root -p
This opens the MariaDB shell and asks for the root password you set earlier. If your system uses socket authentication, sudo mariadb may also work without -u root -p.
Check the default databases
Inside the MariaDB prompt, run:
SHOW DATABASES;
Expected output usually includes:
information_schema
mysql
performance_schema
You should not see the test database if you removed it during the security step. That is a quick sign the hardening script worked as expected.
Why this step matters
This is your first real proof that the server is working. You confirm that login works, the service responds, and the security cleanup took effect. It is much better to verify now than after you connect an application and start debugging.
Step 6: Create a database and user
Create a database
Inside the MariaDB shell, run:
CREATE DATABASE myapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
This creates a new database for your application. Using utf8mb4 is the safer choice because it supports a wider range of characters than older UTF-8 variants.
Create a dedicated user
Run:
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'StrongPass2026!';
This creates a user who can log in only from the local machine. That restriction is useful when your app and database live on the same server.
Grant permissions
Now give the user access to only that database:
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
GRANT assigns access rights, and FLUSH PRIVILEGES reloads the permission tables so the change applies right away.
Why this step matters
Never run your application as the root database user. If the app is compromised, root-level database access gives an attacker too much control. A separate user with limited access is one of the simplest ways to reduce risk on any Linux server.
Step 7: Test the new user
Log in as the app user
Try this:
mariadb -u myapp_user -p myapp_db
If the login works, your user and password are correct. It also confirms the user has access to the database you created.
Run a simple test
Inside the shell, test basic read and write access:
CREATE TABLE test_table (
id INT AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(100)
);
INSERT INTO test_table (value) VALUES ('MariaDB is working!');
SELECT * FROM test_table;
DROP TABLE test_table;
EXIT;
This small test checks table creation, insert, select, and cleanup. If all four steps work, the permissions are set correctly.
Why this step matters
A database can install successfully and still fail when an application tries to write data. This test catches permission problems early, before they become app outages. It is a fast way to confirm the Install MariaDB on Ubuntu 26.04 setup is actually usable.
Step 8: Configure MariaDB on Ubuntu 26.04
Open the config file
For basic tuning, edit:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
This file controls important server settings. You usually place tuning values under the [mysqld] section.
Add simple performance settings
For a small server, you can start with:
[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 100
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 2
These settings help MariaDB use memory better and record slow queries for later review. Slow query logging is useful because it shows problems before users complain.
Restart to apply changes
sudo systemctl restart mariadb
The restart reloads the new configuration. Without it, MariaDB keeps using the old settings.
Why this step matters
A default install works, but a tuned install performs better under real workloads. Even simple tuning can reduce disk reads and help the server stay responsive. If you plan to run WordPress, a custom app, or a dashboard backend, this is where you begin to shape MariaDB for your workload.
Step 9: Optional remote access
Bind MariaDB to a network address
If your app runs on another server, edit the same config file and change:
bind-address = 127.0.0.1
to:
bind-address = 0.0.0.0
This tells MariaDB to listen on all interfaces instead of localhost only.
Create a remote user
On the database side, create a user for the app server IP:
CREATE USER 'remoteuser'@'YOUR_APP_SERVER_IP' IDENTIFIED BY 'StrongPass!';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'remoteuser'@'YOUR_APP_SERVER_IP';
FLUSH PRIVILEGES;
This limits access to one host instead of the whole network.
Why this step matters
Remote access is useful, but it increases risk. If you expose port 3306 too widely, scanners and attackers can find it fast. Keep the bind address and firewall rules as strict as your application allows.
Troubleshooting
1. MariaDB does not start
Check the service:
sudo systemctl status mariadb
Then inspect logs:
sudo journalctl -u mariadb --since "10 minutes ago"
If the port is already in use, another database service may be running. Stop the conflicting service, then start MariaDB again.
2. Access denied for root
Try logging in with:
sudo mariadb
If you enabled socket authentication, this method may work even when mariadb -u root -p does not. If you want password login, confirm that you set the root password during the security step.
3. Package not found
Run:
sudo apt update
Then try the install again:
sudo apt install mariadb-server mariadb-client -y
A stale package index is a common reason Ubuntu cannot find the package. Refreshing the repository list usually fixes it.
4. Cannot connect from another server
Check the bind address in the MariaDB config file. If it still says 127.0.0.1, MariaDB only accepts local connections. Also make sure UFW allows port 3306 from the correct IP or subnet.
5. User can log in but cannot create tables
Check the grants:
SHOW GRANTS FOR 'myapp_user'@'localhost';
If the permissions are too narrow, re-run the GRANT command and then FLUSH PRIVILEGES;. This usually fixes missing access rights.