Debian 11, Debian 10, Debian 9
Ubuntu 20.04, Ubuntu 18.04
Install MariaDB on Debian or Ubuntu and complete the initial configuration. MariaDB is an drop-in replacement for Oracle’s MySQL.
Before getting started, run an obligatory system update. This will make sure you have the latest updates and patches for all installed packages.
sudo apt update && sudo apt upgrade
apt updatedownloads updated package information from all the configured repositories on your system.
apt upgradeupgrades all installed packages to the most recent versions available.
You may also run the command
apt autoremove to uninstall any package dependencies that are no longer needed.
Naturally, the first step in using MariaDB on your server is installing it. The MariaDB version included in the default Debian and Ubuntu repositories tends to be out of date, so it is recommended to add a MariaDB repository to your apt sources. We will be using OSUOSL’s mirror in this bit, but you can choose your own from MariaDB’s repository mirror list.
Start by verifying that the required packages
apt-transport-https are installed.
sudo apt install software-properties-common dirmngr apt-transport-https
Add the repository signing key for MariaDB.
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Add the MariaDB repository for your applicable distribution to the sources list.
# Debian 11 sudo add-apt-repository 'deb [arch=amd64,i386,arm64,ppc64el] https://ftp.osuosl.org/pub/mariadb/repo/10.6/debian bullseye main'
# Debian 10 sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://ftp.osuosl.org/pub/mariadb/repo/10.6/debian buster main'
# Debian 9 sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el,arm64] https://ftp.osuosl.org/pub/mariadb/repo/10.6/debian stretch main'
# Ubuntu 20.04 sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://ftp.osuosl.org/pub/mariadb/repo/10.6/ubuntu focal main'
# Ubuntu 18.04 sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://ftp.osuosl.org/pub/mariadb/repo/10.6/ubuntu bionic main'
Finally, update the sources and install MariaDB using
sudo apt update && sudo apt install mariadb-server
MariaDB is enabled by default, meaning it will automatically start when the system is booted. Check that the MariaDB service is running.
sudo systemctl status mariadb
If all is well, the status should resemble the following.
● mariadb.service - MariaDB 10.6.4 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Fri 2021-04-02 02:22:20 EST; 6min ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 17187 (mariadbd) Status: "Taking your SQL requests now..." Tasks: 8 (limit: 4617) Memory: 73.3M CGroup: /system.slice/mariadb.service └─17187 /usr/sbin/mariadbd
Should the service not be active, make sure you start it before continuing to the next step.
sudo systemctl start mariadb
MariaDB comes packaged with a configuration script to improve the security of your MariaDB server by implementing some basic security recommendations. Execute the script using the included command.
The first step in the script will ask for the current MariaDB
root password. By default there is no root password, so simply press enter to move on.
Enter current password for root (enter for none):
You will then have option to choose between setting a
root password, or using
unix_socket authentication. In this bit, password authentication will be used due to some of the limitations detailed in MariaDB’s Unix Socket documentation.
N when asked about switching to unix_socket authentication, and
Y when asked to change the root password.
Switch to unix_socket authentication [Y/n] N ... Change the root password? [Y/n] Y
Generate a secure password using your password manager of choice, and enter it when prompted.
New password: Re-enter new password:
Following password creation, a series of questions will be presented to complete the basic security setup. All of these should be answered with
Remove anonymous users? [Y/n] Y ... Disallow root login remotely? [Y/n] Y ... Remove test database and access to it? [Y/n] Y ... Reload privilege tables now? [Y/n] Y ... All done! If you've completed all of the above steps, your MariaDB installation should now be secure.