Installing MariaDB on Ubuntu 18.04 from the MariaDB Repositories
At the time of writing this article, the latest version of MariaDB available from the official MariaDB repositories is MariaDB version 10.3. Before continuing with the next step you should visit the MariaDB Repository page and check if there is a new version available.
To install MariaDB 10.3 on your Ubuntu 18.04 server perform the following steps:
- First add the MariaDB GPG key to your system using the following command:
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
- Once the key is imported, add the MariaDB repository with:
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'
If you get an error message saying
add-apt-repository command not foundinstall the
- To be able to install packages from the MariaDB repository you’ll need to update the packages list:
sudo apt update
- Now that the repository is added install the MariaDB package with:
sudo apt install mariadb-server
- The MariaDB service will start automatically, to verify it type:
sudo systemctl status mariadb
● mariadb.service - MariaDB 10.3.8 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 Sun 2018-07-29 19:36:30 UTC; 56s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 16417 (mysqld) Status: "Taking your SQL requests now..." Tasks: 31 (limit: 507) CGroup: /system.slice/mariadb.service └─16417 /usr/sbin/mysqld
And print the MariaDB server version, with:
mysql Ver 15.1 Distrib 10.3.8-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
mysql_secure_installation command to improve the security of the MariaDB installation:
The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately.
All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.
Connect to MariaDB from the command line
To connect to the MariaDB server through the terminal we can use the MariaDB client.
To log in to the MariaDB server as the root user type:
mysql -u root -p
You will be prompted to enter the root password you have previously set when the
mysql_secure_installation script was run.
Once you enter the password you will be presented with the MariaDB shell as shown below:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 49 Server version: 10.1.29-MariaDB-6 Ubuntu 18.04 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.