MariaDB / MySQL 7d ago 19 views 5 min read

How to install MariaDB on Ubuntu 24.04

This guide installs MariaDB 11.2 on Ubuntu 24.04 (Noble) using the official repository. It covers repository setup, server installation, service configuration, and basic security hardening.

Roy S
Updated 1h ago
Sponsored

Cloud VPS — scale in minutes

Instantly deploy SSD cloud VPS with guaranteed resources, snapshots and per-hour billing. Pay only for what you use.

This guide installs MariaDB 11.2 on Ubuntu 24.04 (Noble) using the official repository. It covers repository setup, server installation, service configuration, and basic security hardening. Follow these steps to run a reliable database server on your VPS.

Prerequisites

  • Ubuntu 24.04 LTS (Noble) server with root or sudo privileges.
  • At least 512 MB of RAM available for the database engine.
  • Active internet connection to fetch packages and keys.
  • A static IP address is recommended for production use.

Step 1: Update the package index

Refresh your local package index to ensure you get the latest repository metadata before adding the MariaDB key.

sudo apt update

Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [120 kB]
Get:2 http://archive.ubuntu.com/ubuntu noble InRelease [151 kB]
...
Fetched 3,402 kB in 2s (1,850 kB/s)
Reading package lists... Done

Step 2: Import the MariaDB GPG key

Import the official MariaDB signing key so the system trusts packages from their repository. This prevents security warnings during installation.

curl https://downloads.mariadb.com/MariaDB/GPG-KEY-MariaDB | sudo apt-key add -

You will see a prompt to trust the key. Press Enter to confirm.


gpg: keyring /etc/apt/trusted.gpg.d/gpg-mariadb-mariadb.gpg
gpg: no valid OpenPGP data found.
gpg: Good signature from "MariaDB "
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 9269 57E9 3308 9740 9D90  C8A1 964B 566D 2F71 220D
gpg: marginal trust: 1 full trust: 0 ultimate trust: 0
gpg: Total number of signatures: 1
gpg: Number of valid signatures: 1
gpg: Valid signature from: "MariaDB "

Step 3: Add the MariaDB repository

Add the official MariaDB repository for Ubuntu 24.04. This ensures you get the latest stable version, currently 11.2.x.

curl https://downloads.mariadb.com/mariadb/repo/11.2/ubuntu/24.04/mariadb-archive.gpg | sudo apt-key add -
echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/mariadb.gpg] https://downloads.mariadb.com/mariadb/repo/11.2/ubuntu noble main" | sudo tee /etc/apt/sources.list.d/mariadb.list

The command creates a new file at `/etc/apt/sources.list.d/mariadb.list`. Verify it exists with `ls -l /etc/apt/sources.list.d/mariadb.list`.

Step 4: Install the MariaDB server

Install the MariaDB server package along with its dependencies. The package manager will resolve required libraries automatically.

sudo apt install mariadb-server -y

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  mariadb-server
The following packages will be upgraded:
  mariadb-server-core
...
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.5 MB of archives.
After this operation, 78.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Type Y and press Enter to proceed. The installation process will configure the service files and create the default database user.

Step 5: Secure the MariaDB installation

Run the built-in security script to remove test databases and change default passwords. This is a critical step for production servers.

sudo mysql_secure_installation

Follow the interactive prompts:

  1. Enter current password for root: Press Enter if no password is set yet.
  2. Would you like to disable root login via TCP/IP? Select Y to restrict remote root access.
  3. Remove anonymous users? Select Y to delete the default anonymous user.
  4. Disallow root login remotely? Select Y to prevent remote root access.
  5. Remove test databases? Select Y to delete test_db and test_db2.
  6. Reload privilege tables now? Select Y to apply changes immediately.

The script will output a summary of the changes made. Review this output carefully to confirm the security hardening was successful.

Step 6: Start and enable the service

Start the MariaDB service immediately and configure it to start automatically on boot. This ensures the database is available after a system restart.

sudo systemctl start mariadb
sudo systemctl enable mariadb

Check the service status to confirm it is running in an active state.

sudo systemctl status mariadb

● mariadb.service - MariaDB 11.2.4 MySQL database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2024-05-20 10:00:00 UTC; 5s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 1234 (mariadbd)
    Status: "Ready to accept connections"
   CPU(s): 2
   Memory: 128.0M
   CGroup: /system.slice/mariadb.service
           └─1234 /usr/sbin/mariadbd --basedir=/usr --datadir=/var/lib/mysql ...

Verify the installation

Connect to the MariaDB server using the root user to verify the installation is functional. The default port is 3306.

sudo mysql -u root -p

Enter the root password when prompted. You should see the MariaDB welcome screen.


MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Run a simple query to confirm the server responds to commands.

MariaDB [(none)]> SELECT VERSION();
+-------------+
| version()   |
+-------------+
| 11.2.4-MariaDB |
+-------------+
1 row in set (0.00 sec)

Exit the client with `EXIT;` or `Ctrl+D`.

Troubleshooting

If the service fails to start, check the system logs for specific error messages. Use the journalctl command to inspect recent service logs.

sudo journalctl -u mariadb -xe

Common issues include permission errors on data directories or configuration syntax errors. Ensure the data directory exists and has the correct ownership.

sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 750 /var/lib/mysql

If the service is stuck in a failed state, try restarting it after fixing the underlying issue.

sudo systemctl restart mariadb

Verify the configuration file syntax before restarting to avoid boot failures.

sudo mysql_config_editor check

If you need to reset the root password, use the `ALTER USER` command inside the MySQL client.

sudo mysql -u root -p
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewSecurePassword';
MariaDB [(none)]> FLUSH PRIVILEGES;

Ensure the firewall allows traffic on port 3306 if you plan to accept remote connections. Use `ufw` to manage firewall rules.

sudo ufw allow 3306/tcp

Check the current firewall status to confirm the rule is active.

sudo ufw status

If you encounter SSL certificate errors, generate self-signed certificates for internal use or obtain trusted certificates.

sudo mariadb_ssl_setup

Review the error logs located at `/var/log/mysql/error.log` for detailed stack traces if the service crashes on startup.

Sponsored

Powerful Dedicated Servers — Linux & Windows

Bare-metal performance with SSD storage, DDoS protection and 24/7 expert support. Ideal for production workloads, databases and high-traffic sites.

Tags: mariadbsecurityUbuntuDatabaseLAMP
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

No comments yet — be the first to share your thoughts.