Install MariaDB on Ubuntu and Put It to Work
MariaDB is an open-source relational database server that stores structured information in tables and responds to SQL queries. On Ubuntu, it is a practical choice for a self-hosted website, inventory system, WordPress installation, or small business application because the packages are maintained in the Ubuntu repositories and can be managed entirely from the command line. This gives Australian households and small businesses control over their data without depending on a paid remote database service.
The installation uses Ubuntu’s own packages, a local-only database listener, separate administrator and application accounts, and a simple backup routine. The examples apply to supported Ubuntu LTS releases, including Ubuntu 22.04 and 24.04 LTS, although the packaged MariaDB version will differ between releases.
Install the server with Ubuntu packages
Begin by refreshing the package index and installing the MariaDB server from the standard Ubuntu archive. The server package also provides the mariadb command-line client needed for administration and application testing.
sudo apt update
sudo apt install mariadb-server
The installation usually starts MariaDB through systemd. Enabling it explicitly ensures that the database service also starts after a reboot.
sudo systemctl enable --now mariadb
No separate desktop interface is required for installation or administration. A graphical client such as DBeaver can be added later if it makes browsing schemas more convenient. On a remotely hosted system, configure firewall and SSH access separately; the database should not be exposed directly to the internet.
Check the version and running service
Confirm the installed version and service state with a few simple commands. These checks are useful immediately after installation and after any package upgrade.
mariadb --version
systemctl is-active mariadb
systemctl is-enabled mariadb
The first command reports the server or client version, while the systemd commands return active and enabled when MariaDB is running and configured to start at boot. Ubuntu 24.04 LTS, for example, normally carries the MariaDB 10.11 series, whereas earlier LTS releases use another supported branch.
MariaDB configuration normally lives under /etc/mysql/mariadb.conf.d/, with 50-server.cnf holding common server options. Time settings also matter for audit trails, scheduled jobs, and backup names. Check the host clock with timedatectl status. Australian operators may encounter AEDT in Sydney and Melbourne, AEST in Brisbane, and AWST in Perth; storing consistent timestamps in UTC and converting them for display avoids daylight-saving ambiguity.
Apply a sensible security baseline
A fresh Ubuntu installation normally gives the root MariaDB account local UNIX-socket authentication, allowing administrative access through sudo mariadb. MariaDB also provides a hardening helper that can remove anonymous accounts and the test database while reviewing password and remote-login policies.
sudo mariadb-secure-installation
Use a strong password if one is requested, retain local socket access for the administrator where suitable, and avoid allowing remote root logins. Test the administrative connection in another terminal before closing the current session.
MariaDB normally listens on the loopback interface, 127.0.0.1. Verify the bind-address setting in 50-server.cnf rather than assuming it is restricted. An ufw status check will show whether the Ubuntu firewall is active, but local-only database use needs no public rule for port 3306. This is particularly important on Australian NBN or FTTP connections, where a home router may sit on a public-facing network. Remote administration can use an SSH tunnel instead:
ssh -L 13306:127.0.0.1:3306 ubuntu@server
mariadb -h 127.0.0.1 -P 13306 -u appuser -p
Database access must also account for Australian privacy obligations. Under the Privacy Act 1988, many organisations with an annual turnover of $3 million or more must handle personal information under the Australian Privacy Principles, while some smaller organisations are covered regardless of turnover. If the database contains eligible personal information, access controls, audit practices, encrypted backups, and the Notifiable Data Breaches scheme should be considered as part of the deployment.
Create a database and least-privilege user
Open an administrative session and create a database for an application. The utf8mb4 character set handles multilingual text and modern characters, including the accented and non-Latin names commonly found in Australian communities.
sudo mariadb
CREATE DATABASE app_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'127.0.0.1'
IDENTIFIED BY 'replace-this-with-a-long-random-secret';
GRANT SELECT, INSERT, UPDATE, DELETE
ON app_db.*
TO 'appuser'@'127.0.0.1';
This account is limited to the local loopback address rather than %, so it cannot be used directly from another host. Its permissions cover ordinary application data operations without granting the ability to create users, alter the server, or read unrelated databases. Schema changes can be performed with a separate administrative account or a controlled deployment user.
Generate the password with a password manager or a tool such as openssl rand -base64 24, then store it securely. Do not commit database credentials to a Git repository or leave them in a world-readable application configuration file. CREATE USER and GRANT take effect immediately, so FLUSH PRIVILEGES is unnecessary. If an application connects through a UNIX socket using the hostname localhost, create a matching 'appuser'@'localhost' account and apply the same database grants.
Connect, query, and manage data
Connect as the application user by specifying the loopback address and port. The password prompt keeps the secret out of the shell history.
mariadb -h 127.0.0.1 -P 3306 -u appuser -p app_db
Inside the client, a few queries will confirm the connection and permissions.
SELECT VERSION(), USER(), @@port;
SHOW GRANTS;
SELECT DATABASE();
SHOW TABLES;
The USER() value should identify appuser@127.0.0.1, while SHOW GRANTS should show access only to app_db. If SHOW TABLES reports no tables, that is expected until a schema has been created with an administrative account.
Applications usually connect to 127.0.0.1 over TCP, even when they run on the same machine as MariaDB. Their configuration should include the database name, username, port and a secret supplied through an environment variable or protected configuration file. Application code should use prepared statements rather than concatenating user input into SQL, and multi-step changes should use transactions so incomplete records are not committed. A desktop client can use the same host, port and credentials, but it should never be used as a reason to open port 3306 publicly.
Automate secure backups and updates
MariaDB’s mariadb-dump utility can create a consistent compressed backup for a small InnoDB database. The --single-transaction option avoids locking normal application tables for the duration of the dump.
mkdir -p "$HOME/mariadb-backups"
backup="$HOME/mariadb-backups/app_db-$(date +%F-%H%M).sql.gz"
sudo mariadb-dump --single-transaction --quick --triggers app_db \
| gzip > "$backup"
gzip -t "$backup"
The final command checks that the gzip archive is structurally sound. A backup should also be restored into a separate test database to confirm that it contains usable data.
sudo mariadb -e "CREATE DATABASE restore_test CHARACTER SET utf8mb4;"
gunzip -c "$backup" | sudo mariadb restore_test
sudo mariadb restore_test -e "SHOW TABLES;"
Schedule backups so that a new archive is produced before the oldest one is removed, and keep copies outside the database server. Australian cloud providers offer regions in Sydney, Melbourne, Brisbane, Perth and other locations, but choosing an Australian region does not remove the need to check contractual access, support arrangements, encryption and any jurisdiction-specific requirements. Encrypted off-site storage protects the data if the server or local account is compromised.
Package updates and database maintenance should follow a regular schedule. Review available upgrades, create a fresh backup, and follow any MariaDB upgrade guidance before installing a larger server version.
sudo apt update
apt list --upgraded
sudo journalctl -u mariadb -n 100 --no-pager
Run a small Australian tool-library project
A compact table demonstrates how the administrative and application accounts work together. An administrator creates the schema, while the restricted application user performs routine data operations.
sudo mariadb <<'SQL'
USE app_db;
CREATE TABLE tools (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
suburb VARCHAR(80) NOT NULL,
available_from DATE NOT NULL,
notes TEXT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci;
SQL
Connect with the application account and add records representing a shared neighbourhood tool library. The locations reflect everyday communities across Australian cities rather than a single metropolitan area.
mariadb -h 127.0.0.1 -P 3306 -u appuser -p app_db
INSERT INTO tools (name, suburb, available_from) VALUES
('Cordless drill', 'Newtown, Sydney', CURDATE()),
('Folding ladder', 'Richmond, Melbourne', DATE_ADD(CURDATE(), INTERVAL 2 DAY));
SELECT id, name, suburb, available_from FROM tools ORDER BY id;
UPDATE tools
SET notes = 'Battery and charger included'
WHERE id = 1;
This schema maps directly to a typical application: INSERT adds a booking, SELECT retrieves available equipment, and UPDATE changes its status or notes. Deletions should always include a precise condition, and related changes should be wrapped in a transaction. The next concrete step is to create the initial compressed backup with sudo mariadb-dump --single-transaction --triggers app_db | gzip > "$HOME/mariadb-backups/app_db-initial.sql.gz".