It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In RegisterIt looks like you're new here. If you want to get involved, click one of these buttons!
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).
First, make sure your system is up to date:
apt update && apt upgrade -y
apt install mariadb-server -y
Start MariaDB by executing the following command:
systemctl start mariadb
To configure MariaDB to start automatically at boot, run this command:
systemctl enable mariadb
Verify whether MariaDB has been successfully enabled by checking the status:
systemctl status mariadb
The output should look like this:
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:
In this section, we will walk through the process of using MariaDB to create databases, define tables, and insert data.
Log in to MariaDB as the root user using the newly set password:
mysql -u root -p
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;
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");
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;
When you're done, you can exit the MariaDB shell by typing:
EXIT;