This post will guide you through the installation of MariaDB 10.5 on Ubuntu 16.04 LTS whose code name is Xenial. MariaDB is one of the most popular open source, relational database management systems.
For Ubuntu 18.04 use: Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7
For Debian 9 / Debian 8: How to Install MariaDB 10.x on Debian 9 / Debian 8
MariaDB is a community-developed fork of the MySQL due to concerns over its acquisition by Oracle Corporation. It is intended to remain free under the GNU GPL. The development of MariaDB is led by some of the original developers of MySQL.
Install MariaDB 10.5 on Ubuntu 16.04 LTS
To install MariaDB 10.5 on Ubuntu 16.04, you need to add MariaDB repository on to the system.
sudo apt update
Run the following commands to import MariaDB repository PGP key and add the repository.
sudo apt -y install software-properties-common gnupg-curl sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.5/ubuntu xenial main'
Update system package list and install MariaDB:
sudo apt update sudo apt install mariadb-server mariadb-client
Accept installation using y key
... Reading state information... Done The following additional packages will be installed: galera-4 gawk libaio1 libdbi-perl libgdbm3 libmariadb3 libmpfr4 libpcre2-8-0 libperl5.22 libsigsegv2 lsof mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common mariadb-server-10.5 mariadb-server-core-10.5 mysql-common perl perl-modules-5.22 psmisc rsync socat Suggested packages: gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make Recommended packages: libdbd-mariadb-perl | libdbd-mysql-perl libterm-readkey-perl libhtml-template-perl rename The following NEW packages will be installed: galera-4 gawk libaio1 libdbi-perl libgdbm3 libmariadb3 libmpfr4 libpcre2-8-0 libperl5.22 libsigsegv2 lsof mariadb-client mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common mariadb-server mariadb-server-10.5 mariadb-server-core-10.5 mysql-common perl perl-modules-5.22 psmisc rsync socat 0 upgraded, 24 newly installed, 0 to remove and 2 not upgraded. Need to get 30.8 MB of archives. After this operation, 241 MB of additional disk space will be used. Do you want to continue? [Y/n] y
Secure database installation by setting root password, disable remote root login and remove test databases:
$ sudo mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] y Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Try access to mariadb shell without password
$ mysql -u root <ENTER>
You should get an access denied error which means you need to provide a password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Do the same by providing root password:
$ mysql -u root -p Enter password: <ENTER-PASSWORD> Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.5.4-MariaDB-1:10.5.4+maria~xenial mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SELECT version(); +----------------------------------------+ | version() | +----------------------------------------+ | 10.5.4-MariaDB-1:10.5.4+maria~xenial | +----------------------------------------+ 1 row in set (0.001 sec)
Create a test database
MariaDB [(none)]> CREATE DATABASE test_db; Query OK, 1 row affected (0.001 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test_db | +--------------------+ 4 rows in set (0.002 sec) MariaDB [(none)]> DROP DATABASE test_db; Query OK, 0 rows affected, 2 warnings (0.002 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.001 sec) MariaDB [(none)]> \q Bye
Install Desktop Database Management Tool
If working with MySQL command line is not your thing, then consider installing a Database Tool to help you. Check out our guide below:
Thanks for installing MariaDB 10.3 on Ubuntu 16.04 LTS server. You should now have a working MariaDB database server ready for production use.
Learning Video courses: