
A fresh Ubuntu server is easy to get running. A database that still behaves at 2 a.m. during a traffic spike takes more work. Many MariaDB installs follow the same path: apt install, a quick password, and an application connected within ten minutes. Six months later the same box has swapped itself into a crawl, the root account is reachable from places it shouldn’t be, and nobody remembers where the data directory lives.
This guide covers the install and what comes after it. Ubuntu 26.04 LTS “Resolute Raccoon” was released on April 23, 2026, and it is the 11th long-term supported Ubuntu release. LTS releases get five years of standard security maintenance and are the usual pick for production work. MariaDB is in the default repository, so a working database takes a couple of commands. A database you can trust takes a bit more.
The sections below cover the installation, hardening, authentication quirks, a sensible baseline configuration, performance tuning, backups, and the errors that most often show up in the field. Most commands also work on Debian 12/13 with minor differences, and the RHEL-family differences are noted where they matter (AlmaLinux, Rocky Linux). Treat the numbers in the tuning section as starting points and measure on your own workload.
What You Get on Ubuntu 26.04
The default repository ships MariaDB directly, with no external source required. Community reports from fresh 26.04 servers show the 11.8 series (one user reported 11.8.6). That matters because 11.8 is a long-term support series of MariaDB. Check the exact build on your own machine, since point releases move with security updates.
There are two ways to install it:
| Method | Best for | Trade-off |
|---|---|---|
| Ubuntu default repository | Most servers, simple patching with unattended upgrades | Version is fixed to what Ubuntu packages |
| MariaDB Foundation/Corporation repository | Needing a newer or specific series | You own repo trust and upgrade planning |
For a typical WordPress, Laravel, or Django stack, the distribution package is the right call. Security fixes arrive through the same channel as the rest of the OS, and Ubuntu’s AppArmor profile is already wired up. Add an external repository only when a feature or a client compatibility requirement forces it.
One naming note. Modern MariaDB uses mariadb, mariadb-dump, mariadb-admin and so on as the real binaries. The old mysql* names still exist as compatibility symlinks. Scripts written years ago keep working, but new documentation and automation should use the mariadb names.
Before You Start: Prerequisites
Check these first and you avoid half the troubleshooting section later.
- A server or VM running Ubuntu 26.04 LTS with a sudo-capable, non-root user.
- At least 1 GB of RAM for testing. For production, 4 GB or more is a realistic floor for anything with real traffic.
- Working DNS and outbound access to the Ubuntu mirrors.
- No leftover MySQL packages. Mixed MySQL and MariaDB installs on one host cause confusing socket and package conflicts.
Check the OS release and look for conflicting packages:
lsb_release -a
dpkg -l | grep -Ei 'mysql|mariadb'
If MySQL server packages show up and you don’t need them, remove them before continuing. If a database already holds data, stop and back it up first. Purging a package can remove more than you expect.
Check your free memory and disk now. Databases punish thin disks.
free -h
df -hT /var/lib
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,ROTA
The ROTA column tells you whether the disk is rotational (1) or SSD/NVMe (0). That affects tuning later.
Step 1: Update the System
Patch the base system before installing anything. It sounds boring, but a stale package index is a classic cause of “unable to locate package” and dependency errors.
sudo apt update
sudo apt full-upgrade -y
If the kernel or libc was updated, reboot at a quiet moment:
sudo reboot
On a live box, check whether a reboot is actually required before scheduling downtime:
[ -f /var/run/reboot-required ] && cat /var/run/reboot-required
Step 2: Install the MariaDB Server
The default repository route takes one command:
sudo apt install mariadb-server mariadb-client -y
mariadb-server pulls in the daemon and its dependencies. The client package gives you the mariadb command-line shell. On Ubuntu the package installer starts the service automatically and enables it at boot. Verify instead of assuming:
systemctl status mariadb --no-pager
systemctl is-enabled mariadb
mariadb --version
A healthy status shows active (running). If it isn’t running, jump to the troubleshooting section. The most common causes are a full disk, a bad config file, or an AppArmor denial.
Useful companions that sysadmins tend to install at the same time:
sudo apt install mariadb-backup mytop mysqltuner -y
mariadb-backup supports hot physical backups. mysqltuner is a Perl script that reads server status and suggests changes. Neither is required, but both are worth having on a production host. If a package name isn’t found on your mirror, search with apt search mariadb, because packaging names occasionally shift between releases.
Step 3: Run the Security Script
A fresh install is permissive on purpose. The hardening tool closes the common gaps:
sudo mariadb-secure-installation
Older guides call it mysql_secure_installation. The symlink still works, but the mariadb- name is the current one. Here is what each prompt does and how to answer it on a production box.
- Switch to unix_socket authentication: On Ubuntu the root account already authenticates through the socket, so you can answer yes or no safely. Keeping it means only the OS root user (via sudo) can log in as the database root. That is a feature, not a limitation.
- Change the root password: With socket authentication in place, a root password adds little for local access. Many admins skip it and instead use named admin accounts for remote tooling.
- Remove anonymous users: Yes. Anonymous accounts exist for testing and have no place on a server.
- Disallow root login remotely: Yes. Root should never accept network logins.
- Remove the test database: Yes. It is world-accessible by default in older setups, and nobody needs it.
- Reload privilege tables: Yes.
Prompts differ slightly between versions, so read each question before pressing Y. After the script finishes, confirm the state yourself:
sudo mariadb -e "SELECT user, host, plugin FROM mysql.user;"
sudo mariadb -e "SHOW DATABASES;"
You should see no blank usernames, no wildcard-host root, and no test database.
Step 4: Understand Root Authentication
This is where newcomers get stuck. They run mariadb -u root -p, type a password that was never set, and get “Access denied.” The server is behaving as designed.
The root account uses the unix_socket plugin (or a similar socket-based mechanism). If you are the OS root (or use sudo), you are in:
sudo mariadb
No password prompt. That’s intended. For applications, never use root. Create dedicated users with the narrowest privileges that work.
Step 5: Create a Database and an Application User
Running every app as root is one of the most common and most damaging habits. Compromise one site and the attacker owns every database on the server. Do this instead:
sudo mariadb
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'Use-A-Long-Random-Passphrase-Here';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
A few points on why:
utf8mb4is real UTF-8, including emoji and the full Unicode range. The olderutf8alias historically meant a three-byte subset, which has caused plenty of broken-character tickets.- The collation is explicit here for portability. Newer MariaDB series have moved their default collation, and explicit values avoid surprises when you later import a dump into another server.
'appuser'@'localhost'restricts the account to local connections. If the app runs on another host, create the user for that specific IP, for example'appuser'@'10.0.0.15', rather than'%'.FLUSH PRIVILEGESisn’t strictly needed afterCREATE USERandGRANT, but it does no harm.
Test the new account:
mariadb -u appuser -p appdb -e "SELECT CURRENT_USER(), DATABASE();"
For stricter setups, grant only what the app needs (SELECT, INSERT, UPDATE, DELETE) and give schema-change rights to a separate migration account. It’s more work, but it limits the damage from SQL injection in a real way.
Step 6: Configure MariaDB the Right Way
On Ubuntu, configuration lives under /etc/mysql/. The main file includes snippets from /etc/mysql/mariadb.conf.d/. The one you’ll touch most is 50-server.cnf.
Don’t edit packaged files directly if you can avoid it. Package upgrades may prompt you about conflicts. A cleaner pattern is a separate drop-in file:
sudo nano /etc/mysql/mariadb.conf.d/99-custom.cnf
Files loaded later override earlier ones, so a 99- prefix wins. This also gives you one place to see your changes with git or a configuration management tool.
A sensible baseline for a mid-size server with 8 GB of RAM running mostly InnoDB:
[mariadbd]
# Networking
bind-address = 127.0.0.1
skip-name-resolve = 1
# Character set
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
# Connections
max_connections = 200
thread_cache_size = 32
# InnoDB
innodb_buffer_pool_size = 4G
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
# Logging
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 1
Why each of these matters:
bind-address = 127.0.0.1keeps the service off the network. Change it only when remote access is truly needed.skip-name-resolvestops DNS lookups on every connection. A slow resolver can add seconds of latency, and it removes a whole class of “random slow login” complaints. Remember that grants must then use IP addresses, not hostnames.innodb_buffer_pool_sizeis the single most important setting. It caches data and indexes in RAM.innodb_flush_log_at_trx_commit = 1is full ACID durability. Setting it to 2 improves write speed, but you can lose about a second of transactions on a crash. For payments or orders, keep it at 1.O_DIRECTavoids double buffering through the OS page cache.- The slow query log is cheap and gives you evidence for optimization later.
The section header in modern MariaDB can be [mariadbd], and [mysqld] still works. Using [mariadbd] also keeps these settings away from a stray MySQL install.
Make sure the log directory exists and is writable by the service user:
sudo mkdir -p /var/log/mysql
sudo chown mysql:mysql /var/log/mysql
Validate the config before restarting. Catching a typo here is better than a failed restart in production:
sudo mariadbd --help --verbose 2>&1 | head -n 5
sudo systemctl restart mariadb
sudo systemctl status mariadb --no-pager
Check that your values took effect:
sudo mariadb -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
One trap with innodb_log_file_size: recent MariaDB versions can resize the redo log on restart, but on older habits people deleted ib_logfile* by hand. Don’t do that. Let the server handle it and review the error log if anything looks off.
Step 7: Lock Down the Firewall and Network
If the database only serves a local application, you need no firewall rule at all. The service listens only on loopback. That is the best firewall rule: nothing exposed.
When a separate app server needs access, open the port to that one address only. With UFW:
sudo ufw allow from 10.0.0.15 to any port 3306 proto tcp
sudo ufw status numbered
And change the bind address to the private interface:
bind-address = 10.0.0.10
Never expose 3306 to 0.0.0.0/0. Automated scanners find open database ports within hours, and brute-force attempts follow. If remote administration is needed, tunnel through SSH:
ssh -L 3307:127.0.0.1:3306 admin@db.example.com
Then connect your GUI client to 127.0.0.1:3307. This keeps the database private while you still get remote access.
On AlmaLinux or Rocky, the equivalent is firewall-cmd:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.15" port port="3306" protocol="tcp" accept'
sudo firewall-cmd --reload
For encrypted connections between hosts, enable TLS. Generate or provide certificates, then add to the config:
ssl_cert = /etc/mysql/ssl/server-cert.pem
ssl_key = /etc/mysql/ssl/server-key.pem
ssl_ca = /etc/mysql/ssl/ca-cert.pem
Require it per user when you need to:
ALTER USER 'appuser'@'10.0.0.15' REQUIRE SSL;
Performance Tuning That Actually Matters
Tuning guides are full of magic numbers. Most of the gains come from a handful of changes, so work in this order.
Memory and the Buffer Pool
On a dedicated database server, set the InnoDB buffer pool to roughly 60 to 70 percent of RAM. On a shared box that also runs Nginx and PHP-FPM, go lower, around 25 to 40 percent. Check whether the buffer pool is working:
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';
Compare Innodb_buffer_pool_reads (disk reads) with Innodb_buffer_pool_read_requests (logical reads). If disk reads are more than about 1 percent of requests under normal load, the pool is probably too small or the working set is large.
Watch for swapping. A database that swaps is a database in trouble.
vmstat 1 5
swapon --show
Lowering swappiness on a database host helps the kernel prefer dropping cache over swapping process memory:
echo 'vm.swappiness = 10' | sudo tee /etc/sysctl.d/99-mariadb.conf
sudo sysctl --system
CPU and Connections
More connections do not mean more throughput. Past a point, extra threads just fight over CPU and locks. If an application opens hundreds of connections, a pool (in the app, or a proxy such as ProxySQL) beats raising max_connections. Watch the high-water mark:
SHOW GLOBAL STATUS LIKE 'Max_used_connections';
SHOW GLOBAL STATUS LIKE 'Threads_running';
Threads_running consistently above your core count usually signals slow queries, not a shortage of connections.
Disk I/O
Storage is where databases usually bottleneck. NVMe makes a visible difference for write-heavy loads. Keep the data directory on a dedicated filesystem when you can, and use XFS or ext4 with sensible mount options. Check I/O pressure live:
sudo apt install sysstat iotop -y
iostat -xz 1 5
sudo iotop -oPa
Watch await and %util. High values with a modest query count point to disk saturation. For SSDs, innodb_io_capacity can be raised to match what the device can deliver (for example 2000 or higher on NVMe), while spinning disks should stay near the default.
Query-Level Work
Hardware and settings only go so far. A single missing index can outweigh all of the above. Turn on the slow log (done in the config above) and analyze it:
sudo apt install percona-toolkit -y
sudo pt-query-digest /var/log/mysql/mariadb-slow.log | head -n 60
Then use EXPLAIN on the worst offenders:
EXPLAIN SELECT * FROM orders WHERE customer_id = 4821 ORDER BY created_at DESC LIMIT 20;
If you see type: ALL on a large table, add an index that matches the filter and sort columns. A composite index on (customer_id, created_at) would fix the query above.
Network
For app-to-database traffic across hosts, keep them in the same region and network zone. Round-trip latency multiplies across chatty ORMs that fire dozens of queries per page. Check latency with ping and mtr, and reduce query counts before you reach for bigger servers.
Troubleshooting Common Errors
The service fails to start
Read the real error before guessing:
sudo systemctl status mariadb --no-pager -l
sudo journalctl -u mariadb -n 100 --no-pager
sudo tail -n 100 /var/log/mysql/error.log
Typical causes are a typo in a custom config file, a full disk, wrong ownership on the data directory, or a buffer pool size larger than available memory. Check disk and inodes:
df -h; df -i
ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
This is the socket authentication behavior described earlier. Use sudo mariadb. If you truly need password login for root (not recommended), you can change the plugin, but a dedicated admin user is the better choice:
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'A-Strong-Passphrase';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
ERROR 2002: Can’t connect through socket
The client is looking for /run/mysqld/mysqld.sock and the server isn’t running, or it uses a different path. Check:
ls -l /run/mysqld/
sudo systemctl start mariadb
ERROR 1045: Access denied (using password: YES)
Wrong password, or the host part of the account doesn’t match where the connection comes from. 'appuser'@'localhost' is not the same as 'appuser'@'127.0.0.1' in some setups, especially when skip-name-resolve is on. Inspect the accounts and create the one you need.
Too many connections
Check what is holding them:
SHOW FULL PROCESSLIST;
Kill runaway queries if needed, fix the app’s connection handling, and only then consider raising max_connections (and make sure RAM can support it).
Remote connections time out or refuse
Work through it in order: is the service listening on the right address (ss -tlnp | grep 3306), does the firewall allow the source IP, does the user exist for that host, and does the cloud provider’s security group allow it? Four checks, and the answer is nearly always one of them.
Upgrades behave oddly after a release upgrade
If you moved a server from an earlier Ubuntu release, run the upgrade tool and check the error log after the first start:
sudo mariadb-upgrade
Always snapshot or back up before a major version jump. Rolling back a data directory after an in-place upgrade is not something you want to learn on the fly.