MariaDB is a relational database management system (RDBMS) that provides all the essential features for efficient storage, management and processing of structured data.
1. Installation Guide
1.1. Update your system
First, make sure your system is up to date:
apt update && apt upgrade -y
1.2. Install MariaDB
apt install mariadb-server -y
1.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
1.4. Check MariaDB status
Verify whether MariaDB has been successfully enabled by checking the status:
systemctl status mariadb
The output should look like this:
1.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:
Set the root password;
Remove anonymous users (enter "Y");
Disallow root login remotely (enter "Y");
Remove the test database (enter "Y");
Reload privilege tables (enter "Y").
2. Working with MariaDB
In this section, we will walk through the process of using MariaDB to create databases, define tables, and insert data.
2.1. Log in to the MariaDB
Log in to MariaDB as the root user using the newly set password:
mysql -u root -p
2.2. 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;
2.3 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");
2.4. 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;
2.5. Exit from MariaDB
When you're done, you can exit the MariaDB shell by typing:
EXIT;