Installing MariaDB (Ubuntu)

Last Updated on: 

MariaDB is an open-source relational database, and a fork of MySQL by the original developers of MySQL. The database structure and indexes of MariaDB are the same as MySQL. So, you can easily switch from MySQL to MariaDB with no hassle.

The good thing about MariaDB is that it is built upon the values of performance, stability, and openness.

In this guide, you’ll learn how to install MariaDB on Ubuntu, lets get started…

To install MariaDB, you’ll need to install the mariadb-server package:

					

sudo apt install mariadb-server

Once its done, confirm mariadb existence with whereis mariadb, this would show you where mariadb is installed, in my case, it is: /usr/bin/mariadb

The next thing you’ll want to do is to make sure the service is started and enabled, use the following command to confirm:

● mariadb.service - MariaDB 10.1.44 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-06-24 10:50:56 UTC; 5min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 4745 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 2317)
   CGroup: /system.slice/mariadb.service
           └─4745 /usr/sbin/mysqld

As you can see mariadb is running, and also enabled, meaning when you restart your server, it’s gonna boot up automatically.

To secure your MariaDB installation, run the following command:

					

sudo mysql_secure_installation

Note: The mysql isn’t a typo, mariadb still references mysql

This is a shell script that helps you improve the security of your MariaDB installation, for example:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the localhost.
  • You can remove anonymous-user accounts.
  • You can remove the test database, which by default can be accessed by anonymous users.

The script is self-explanatory, the first thing it would tell you to do is to set a root password, please note that the root user for MariaDB is not the same as the root user on your system, so, make sure the Password you are creating for the MariaDB root user differs.

Setting the root password ensures no one logs into MariaDB root without proper authorization.

The next step is to skip the “change root password” by entering n, you don’t need this as you have already set it in the first phase.

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 it by entering Y.

The next step is to disallow remote access to the database server, root should be allowed to connect from ‘localhost’ only as it is a bad idea allowing external access to MariaDB, your users only need access to the website, not the database server.

So, enter Y

The next step is to remove the anonymous user as this is only for testing purposes, so, enter Y

Lastly, enter Y to reload the privilege table, this way, it would ensure all the changes made so far will take effect immediately.

If you’ve done all the above, then your mariadb is secure and you are good to go:

This is the complete log of the process, you can skip this:

pascal@blog:~$ 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): ► Input Password Here
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

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!

To connect to your MariaDB server, you’ll use the mariadb command to access the MariaDB shell, run the following command to connect to mariadb:

This would connect as root, the root is assumed if you are attempting to access MariaDB with sudo, you’ll be presented with the following:

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 47
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Now, you can start managing your DB, to exit, type exit or CRTL D to quit.

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php