In this article, we will show you how to install MariaDB on a Debian 9 Cloud VPS.
Step 1. Log into your Server
First things first, login to your Debian 9 Cloud VPS via SSH as the root user:
ssh [email protected]<span style="color: #ff0000;">IP_Address</span> -p <span style="color: #ff0000;">Port_number</span>
Make sure to replace IP_Address and Port_number with your server’s IP and SSH port.
Step 2. Install MariaDB
Method 1. Install from the Debian Repository
Installing MariaDB from the Debian base repository is a straightforward method of installing MariaDB, but doing this may lead to an older version being installed. If you need the latest version of MariaDB, you can install it through the official MariaDB repository, as shown in Method 2.
sudo apt update sudo apt -y install mariadb-server mariadb-client
Run the command
mysql_secure_installation to perform the initial setup of MariaDB server once you’ve installed it. Let’s see how:
Method 2. Install MariaDB from MariaDB Repositories
Before continuing with the installation you can visit the MariaDB Repository page and check the latest MariaDB version. At the time of writing this article, the latest version of MariaDB was 10.3.
To install MariaDB 10.3 on your Debian 9 system, follow these steps:
The first step is to enable the MariaDB repository and import the repository GPG key to your system. To do so, run the following commands:
sudo apt install software-properties-common dirmngrsudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.dotsrc.org/mariadb/repo/10.3/debian stretch main'
Once the repository is enabled, update the packages list and install MariaDB with these next two commands:
sudo apt update sudo apt install mariadb-server
In case you want to start/stop MariaDB, you can use the following commands.
sudo systemctl start mariadb sudo systemctl stop mariadb
Let’s verify that MariaDB is running.
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
To enable the MariaDB service on system boot, run the following command:
systemctl enable mariadb
In case you want MariaDB disabled on system boot, run the following command:
systemctl disable mariadb
Step 3. Secure MySQL Installation
Execute the following command on your server. For the highest level of security, answer all prompts with yes by entering the character “y“.
This program enables you to improve the security of your MariaDB installation in the following ways:
- Sets a password for root accounts.
- Remove root accounts that are accessible from outside the local host.
- Removes anonymous user accounts.
- Removes the test database.
The script is fully interactive and prompts for each step in the process.
Now that MariaDB is installed and secured, let’s go over logging into the MariaDB CLI.
Connect to MariaDB from the Command Line
To connect to the MariaDB server through the terminal using the root account, type and execute the following command:
mysql -u root -p
You will be prompted to enter the root password you have previously set up using the
Once you enter the password, you should be able to see the following output:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5635 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
You can now create a database by typing the following command:
CREATE DATABASE your_database; CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON your_database.* TO [email protected]; FLUSH PRIVILEGES; quit
To view MariaDB’s command list from within the client, type:
General information about MariaDB can be found at
You can now create databases, tables, users, and perform everything that you need easily with MariaDB. If you need extra help with MariaDB, there are countless resources online detailing the specific features of this SQL-based server.
Of course, you don’t have to install MariaDB on Debian 9 if you use one of our Managed Cloud VPS Hosting services, in which case you can simply ask our expert Linux admins to install MariaDB on Debian 9 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install MariaDB on Debian 9, please share it with your friends on the social networks using the share shortcuts, or simply leave a reply below. Thank you.