How To Install and Secure MariaDB 10.x on Ubuntu 18.04

How To Install and Secure MariaDB 10.x on Ubuntu 18.04

Forked from MySQL, created with love by original MySQL developers, MariaDB is one of the most popular open source database platforms to this date.

MariaDB is guaranteed to stay open source. In this guide, we are going to see how to install MariaDB 10.x on Ubuntu 18.04. 

Using CentOS 7.0? Here is the guide on How To Install and Secure MariaDB 10.x on CentOS 7.0.

Step 1: Update Ubuntu

We are going to start the installation of MariaDB by first updating the Ubuntu 18.04 operating system. Simply run the following command to fully update 

$ sudo apt update
$ sudo apt dist-upgrade

Step 2: Install MariaDB

Since MariaDB 10.x is already included in the Ubuntu 18.04 repository, the installation of MariaDB is very straightforward using the following command. We are going to install both MariaDB server and client component:

$ sudo apt install mariadb-server mariadb-client

Step 3: Enable and Start MariaDB service

We are going to enable MariaDB Server to auto start during boot then start the service.

$ systemctl enable mariadb
$ systemctl start mariadb

Step 4: Securing MariaDB

MariaDB comes with a built-in script to help secure a MariaDB server. The requires several user inputs. The following command will start the securing script:

$ sudo mysql_secure_installation

Step 5a: Set root Password

Type in y when asked to set root password and type in the new password twice.

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):

OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

Set root password? [Y/n] y

New password:
Re-enter new password:
Password updated successfully!

Reloading privilege tables..
... Success!

Step 5b: Remove Anonymous User

Type in y to remove the built-in anonymous user.

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!

Step 5c: Prevent root Access outside localhost

Type in y to disallow root access into the database outside the server itself. 

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!

Step 5d: Remove Built-in Database

Type in y to remove the built-in database named test.

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!

Step 5e: Apply Privileges

Type in y to apply all the changes thus far. 

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!

Step 6: Test Database Access

At this point, the MariaDB server is fully configured and ready to serve. Connect to the database to ensure root credential is working. 

$ mysql -u root -p
MariaDB [(none)]>

Congratulations! Your MariaDB Server 10.x is now fully configured and secured on Ubuntu 18.06. 


Print   Email