frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How To Install MariaDB on Ubuntu/Debian

MichailMichail Moderator
edited December 11 in Various Tutorials

Introduction

MariaDB is a relational database management system (RDBMS) that provides all the essential features for efficient storage, management and processing of structured data.

In this guide we will install MariaDB on Ubuntu (starting from 20.04 version) and Debian (starting from 11 version).

Installation Guide

1. Update your system

First, make sure your system is up to date:

apt update && apt upgrade -y

2. Install MariaDB

apt install mariadb-server -y

3. Start and Enable the MariaDB

Start MariaDB by executing the following command:

systemctl start mariadb

To configure MariaDB to start automatically at boot, run this command:

systemctl enable mariadb

4. Check MariaDB status

Verify whether MariaDB has been successfully enabled by checking the status:

systemctl status mariadb

The output should look like this:

5. Secure MariaDB

By default, MariaDB is not secured. To enhance its security, execute the security script:

mysql_secure_installation

The root password is blank by default, so press Enter to continue.

You will need to:

  1. Set the root password;
  2. Remove anonymous users (enter "Y");
  3. Disallow root login remotely (enter "Y");
  4. Remove the test database (enter "Y");
  5. Reload privilege tables (enter "Y").

Working with MariaDB

In this section, we will walk through the process of using MariaDB to create databases, define tables, and insert data.

Log in to the MariaDB

Log in to MariaDB as the root user using the newly set password:

mysql -u root -p

Create a database

Once you have accessed the MariaDB shell, you can create a new database by running the following command (replacing database_name with the desired name):

CREATE DATABASE database_name;

To verify that the database was created successfully, you can list all existing databases by running the following command:

SHOW DATABASES;

To start working with the newly created database, you need to select it by executing the following command:

USE database_name;

Create Table

After selecting the database, you can proceed to create tables and insert data. For example, to create a simple table, use the following command:

CREATE TABLE employees (id INT, name VARCHAR(20), surname VARCHAR(20));

To insert data into the employees table, use the following command:

INSERT INTO employees (id,name,surname) VALUES(01,"John","Smith");

Create a user

To add a new user in MariaDB, execute the following SQL command:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';

Replace newuser with your preferred username.
Replace user_password with a strong password for the new user.

After creating the user, you'll need to grant the necessary privileges. For example, to grant all privileges on a specific database, use the following command (be sure to replace database_name with the actual name of your database):

GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';

To ensure that the privileges are applied, you can execute the following command:

FLUSH PRIVILEGES;

Exit from MariaDB

When you're done, you can exit the MariaDB shell by typing:

EXIT;

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch