MariaDB is an open-source database management system which serves as an alternative for the MySQL portion of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack.
In fact, It is intended to be a drop-in replacement for MySQL and Debian now only ships with MariaDB packages. Therefore, if you attempt to install MySQL server related packages, you'll receive the compatible MariaDB replacement versions instead.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related MariaDB queries.
In this context, we shall look into how to install MariaDB on a Debian 9 server.
How to Install MariaDB on Debian Linux System ?
Before proceeding with this installation procedure, ensure that you use a Debian 9 server with a non-root sudo enabled user account.
Once, ready, perform the steps below.
1. Install MariaDB
By default, MariaDB version 10.1 is included on Debian 9 in the APT package repositories.
So first, update the package index on your server with apt:
$ sudo apt update
After that, install package by typing:
$ sudo apt install mariadb-server
It will start automatically MariaDB service.
2. Secure MariaDB
To increase security of MariaDB installation run the included security script.
This will remove less secure default options such as root remote login and remove sample users.
Now to Secure MariaDB, Run the below command :
$ sudo mysql_secure_installation
At first, it will prompt you to enter current root user password.
Next, it will ask you weather you want to change or set password for root.
Press N and hit Enter key.
After that it will prompt series of questions, press Y and hit 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 respects the changes you have made.
3. Verify MariaDB Installation & Service
Execute below command to check MariaDB service status:
$ sudo systemctl status mariadb
It will show output as following :
● mariadb.service - MariaDB 10.1.37 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-03-22 16:36:30 UTC; 48min ago
Main PID: 482 (mysqld)
Status: "Taking your SQL requests now…"
Tasks: 27 (limit: 4915)
How to Connect to MariaDB from the command line ?
You can also connect MariaDB server through the terminal as the root account by typing:
$ mysql -u root -p
You will be prompted to enter the root password.
Enter root user password which you set at securing step.
Once you will enter correct password it will show MariaDB shell as shown below:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[Need urgent assistance in fixing MariaDB Installation errors on Ubuntu Linux System? We can help you. ]