Preliminaries
MariaDB is the community-developed fork of the popular MySQL relational database management system (RDBMS). The project began when the company that developed MySQL was acquired by Oracle. It intends to be a drop-in replacement for MySQL and will have complete compatibility with applications that work with MySQL. Stack Harbor loves open-source — and as such we roll MariaDB for our turnkey Stacks and tutorial topics. In this tutorial, we’ll show you how to install the MariaDB packages so that you can run your own database server and interact with it using the MariaDB client.
This tutorial assumes that you’ve followed our “Getting Started With Your Stack” tutorial and have set up a non-root user with sudo privileges. Let’s get started.
Installing the Software
We should always update our package repositories before we install any packages. This ensures that we have the latest versions of packages that we install, including security patches.
sudo apt-get update
Now we can install the MariaDB package and the necessary development libraries that are required for software to interact with the MariaDB server.
sudo apt-get install mariadb-server libmariadbd-dev
During the course of the installation, you will be prompted with a pink screen corresponding to the Debian Configuration manager. It will ask you to set a root password for your MariaDB server. If you don’t wish to set a root password right now, you can leave this blank and just press return/enter until the installation resumes. However, we highly encourage you to set a secure root password right now and keep it safe, for if someone were to get access to your Stack using any user they would be able to perform catastrophic actions to your DB server (such as drop databases/tables).
Finishing Up and Interacting With the Client
Once your installation has completed, you can verify that you have a working installation of MariaDB by running the following command:
mysql -u root -p
This will prompt you for your password and allow you to authenticate with the MariaDB client. If you successfully authenticate, you will see the MariaDB prompt that looks similar to the following:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 70 Server version: 5.5.44-MariaDB-1ubuntu0.14.04.1 (Ubuntu) Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
The last line is your MariaDB shell prompt. The [(none)] will change to reflect the database you are currently interacting with. If you go ahead and issue the command USE mysql; into the prompt, you will see the ‘none’ change to ‘mysql’. Now that we know that everything is working, we’ll secure the installation by removing anonymous users and test databases. Enter ‘\q’ into the MariaDB shell to exit and return to your system shell.
MariaDB (and MySQL) come prepackaged with a script called mysql_secure_installation. In your system shell, enter the name of the script and hit enter. You will be prompted to enter your root password once again. If you left this blank earlier, press enter when you are prompted for it. The script will ask you if you want to change your root password, which you should do if you believe that you can create a more secure password or if you previously left the root password empty. After this step, you’ll be asked if you want to remove anonymous users, remove test databases, and flush user privileges. You should accept all of the prompts in order to secure your database and complete the installation.
Final Words
Congratulations! You’re ready start explore the power of MariaDB as a RDBMS. You can start stacking existing packages on top of MariaDB that require a database system or just use this Stack as a remote database server and benefit from the power of separating your application and database servers. Check our our community section for more tutorials on MariaDB and other server & development tasks. From all of us at Stack Harbor, ahoy!