Make sure your Ubuntu is up to date and patched.
$ sudo apt update $ sudo apt upgrade
MariaDB is available within Ubuntu’s default software repositories, making it possible to install it using conventional package management tools. After confirming the installation,
apt will install MariaDB and all required dependencies.
$ sudo apt install mariadb-server
Check MariaDB / MySQL version
$ mysql -V # OUTPUT mysql Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
These commands will install MariaDB, but will not prompt you to set a password or make any other configuration changes. Because the default configuration leaves your installation of MariaDB insecure, we will use a script that the
mariadb-server package provides to restrict access to the server and remove unused accounts. This script changes some of the less secure default options for things like remote root logins and sample users.
$ sudo mysql_secure_installation
The first prompt will ask you to enter the current database root password. Since you have not set one up yet, press
ENTER to indicate “none”. The next prompt asks you whether you’d like to set up a database root password. On Ubuntu, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Type
N and then press
From there, you can press
Y and then
ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MariaDB immediately implements the changes you have made.
With that, you’ve finished MariaDB’s initial security configuration.