Guides 11792 Published by

This quick‑start guide walks you through installing MariaDB 10.x on Ubuntu 22.04 or 20.04 without relying on the default MySQL packages, so you can drop a lightweight replacement into your server or dev box in less than ten minutes. It begins by removing any old MySQL or MariaDB binaries, then adds the official repository key and source list, updates the package lists, installs the server and client, runs the security script to set a root password and harden defaults, and finally verifies that the service is running. Optional steps let you replace the legacy mysql binary with the MariaDB shell and warn about common pitfalls such as old init scripts or port collisions that could prevent the daemon from starting. Once installed, you can import dumps, enable SSL or replication, and keep tabs on community forums for extensions that might save you time in the future.





MariaDB 10.x on Ubuntu 22.04 or 20.04: A Quick‑Start Guide

If you’re looking to run a lightweight, drop‑in replacement for MySQL on your server or dev box, this walk‑through will get MariaDB 10.x up and running in under ten minutes—no “official” repositories needed.

Why go with MariaDB 10.x?

I’ve seen folks complain about the lack of certain features in Ubuntu’s default MySQL package (like the newer JSON functions). MariaDB 10.x fills that gap while staying fully compatible with existing scripts. Plus, its community‑driven development means you get updates faster than a typical LTS stack.

Step 1: Clean up any old MySQL/MariaDB packages
sudo apt purge mysql-server mysql-client mysql-common mariadb-server mariadb-client
sudo apt autoremove

A stale package can lock the /etc/mysql directory or leave behind service files that interfere with a fresh install.

Step 2: Add the MariaDB repository key and source list
wget -qO- https://mariadb.org/mariadb_release_signing_key.asc | sudo apt-key add -

This verifies the authenticity of packages you’ll pull next. Trust me—no one wants a rogue repo.

Now pick your version. For MariaDB 10.x:

# On Ubuntu 22.04 (Jammy) or 20.04 (Focal)
echo "deb [arch=amd64] http://mirrors.edge.kernel.org/mariadb/repo/10.11/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb.list

Using the official mirror ensures you get the latest 10.x releases and security patches.

Step 3: Update package lists
sudo apt update

A quick sanity check—if you see “404 Not Found” for the MariaDB repo, double‑check the version string or your Ubuntu codename ($(lsb_release -cs)).

Step 4: Install MariaDB 10.x server and client
sudo apt install mariadb-server mariadb-client

The -server package pulls in the daemon plus its default data directory. The -client gives you the mysql shell.

Step 5: Secure the installation

Run the built‑in script:

sudo mysql_secure_installation

You’ll be prompted to set a root password, remove anonymous users, disallow remote root logins, and drop the test database. I usually leave “Yes” on everything except maybe keeping the test DB for quick demos.

Step 6: Verify MariaDB is running
sudo systemctl status mariadb

You should see active (running) in green. If not, journalctl -xe will give you clues.

Step 7 (Optional): Switch from MySQL client to MariaDB shell

If you still have a MySQL binary around:

sudo mv /usr/bin/mysql /usr/bin/mysql_old
sudo ln -s /usr/bin/mariadb /usr/bin/mysql

Now mysql -u root -p actually calls the MariaDB client. Handy if legacy scripts call mysql.

Common gotchas
  • Old init scripts: On Ubuntu 22.04, older MySQL packages may leave an /etc/init.d/mysql script that conflicts with systemd. The purge in Step 1 usually clears this.
  • Port collisions: If you have another database server on port 3306, MariaDB will fail to start. Check sudo ss -tlnp | grep :3306.
Real‑world observation

Last month I patched a client’s machine after a driver update broke the network interface. The MySQL service was silently refusing connections because of a stale socket file left behind by an older package. Removing it in Step 1 and reinstalling MariaDB resolved the issue instantly—no reboot required.

Done! What next?

You can now:

  • Drop your .sql dump files into /var/lib/mysql or use mysql -u root < dump.sql.
  • Configure replication, SSL, or any other advanced feature you’d normally do on MySQL.
  • Keep an eye on the MariaDB forums for community‑sourced extensions that might save you a few hours of debugging.