Tutorial: Install MariaDB on Ubuntu

MariaDB is a popular open-source relational database management system that’s a drop-in replacement for MySQL. It’s known for its stability, security, and scalability. In this tutorial, we’ll show you how to install MariaDB on Ubuntu and get started with the basics.

Step 1: Update Packages

Before we start, we should update the package list and upgrade any existing packages on the server.

sudo apt update
sudo apt upgrade

Step 2: Install MariaDB

MariaDB is available in the default Ubuntu repositories, so we can install it using apt.

sudo apt install mariadb-server

This command will install MariaDB and all its dependencies.

Step 3: Secure MariaDB Installation

Once the installation is complete, you should secure the MariaDB installation by running the mysql_secure_installation script.

sudo mysql_secure_installation

You will be prompted to enter the root password.
Since this is a fresh installation, there is no root password yet.
Simply press Enter to proceed.

Enter current password for root (enter for none):

You will then be asked if you want to set a root password.
Type “Y” for yes and then enter a strong password when prompted.

Set root password? [Y/n] Y
New password:

You will be asked to confirm the root password.
Type it again and press Enter.

Re-enter new password:

You will be asked to remove anonymous users.
Type “Y” for yes.

Remove anonymous users? [Y/n] Y

You will be asked to disallow root login remotely.
Type “Y” for yes.

Disallow root login remotely? [Y/n] Y

You will be asked to remove the test database and access to it.
Type “Y” for yes.

Remove test database and access to it? [Y/n] Y

Finally, you will be asked to reload the privilege tables.
Type “Y” for yes.

Reload privilege tables now? [Y/n] Y

That’s it! Your MariaDB installation is now secure.

Step 4: Verify Installation

After the installation is complete, you can verify that MariaDB is running by accessing the MariaDB shell.

sudo mysql

You should see the MariaDB prompt.

MariaDB [(none)]>

Step 5: Create a Database

Now that MariaDB is installed and secured, we can create a new database.

CREATE DATABASE mydatabase;

This command will create a new database called mydatabase.

Step 6: Create a User and Grant Permissions

We should create a new user and grant it permissions to access the mydatabase database.

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

This command will create a new user called myuser with a password of mypassword.
We then grant the user all privileges on the mydatabase database.

Step 7: Verify User Access

You can verify that the user has access to the database by accessing the MariaDB shell as the new user.

sudo mysql -u myuser -p

Enter the password when prompted.

Enter password:

You should see the MariaDB prompt for the new user.

MariaDB [(none)]>

You have now successfully installed MariaDB on Ubuntu and created a new database and user. You can now configure MariaDB for your specific needs, such as creating tables and inserting data.

Scroll to top