Saturday, December 28, 2024
Google search engine
HomeData Modelling & AIHow To Install MariaDB 11.0 on Ubuntu 22.04|20.04|18.04

How To Install MariaDB 11.0 on Ubuntu 22.04|20.04|18.04

A relational database management system (RDBMS) was designed with the aim of giving you a way of organizing and storing your data in a structured and efficient manner. MariaDB is one of the widely used RDMS available to open source people. MariaDB is a free to use and powerful database server with a wide range of benefits and features to its users. This database management system was created as a community-driven alternative to the Oracle’s MySQL database system and it is now a popular choice for businesses and organizations of all sizes.

Some of the key features of MariaDB database server are listed below.

  • ACID compliance: Ensures reliability and consistency in database transactions.
  • Has advanced security features such as SSL/TLS support and data encryption
  • JSON support: Support for JSON (JavaScript Object Notation) data types
  • With MariaDB you get flexible storage engines – InnoDB, MyRocks, and Aria
  • It is compatible with MySQL and other relational database systems
  • Powerful query optimization and indexing features for fast data retrieval
  • Existence of database administration and management tools, including MariaDB Monitor and MariaDB Backup

As of this article writing MariaDB 11.0 is not stable and should only be used for testing purposes and not to run production services.

Warning: Do not use alpha / RC releases in production!

You can read the official MariaDB pages to see what’s new and improvements in MariaDB 11.x.

For install on Rocky / AlmaLinux use:

Installing MariaDB 11.0 on Ubuntu 22.04 / 20.04 / 18.04

Follow the steps provided in this section to have a running instance of MariaDB database on your Ubuntu system.

Step 1: Update your system

We always begin our installations with system update.

sudo apt update && sudo apt -y upgrade

If a reboot is needed after the upgrade proceed to do so.

[ -f /var/run/reboot-required ] && sudo reboot -f

Once the upgrade is done you can go to the next step.

Step 2: Add MariaDB APT repository

Next we add the repository that contains the packages we need to install MariaDB 11.x on Ubuntu system.

curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=11.0

Expected output from command execution.

# [info] Checking for script prerequisites.
# [warning] Found existing file at /etc/apt/sources.list.d/mariadb.list. Moving to /etc/apt/sources.list.d/mariadb.list.old_1
# [info] MariaDB Server version 11.0 is valid
# [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
# [info] Adding trusted package signing keys...
# [info] Running apt-get update...
# [info] Done adding trusted package signing keys

Step 3: Install MariaDB 11.0 server / client

Next we install MariaDB server and client packages from configured repositories.

sudo apt update
sudo apt -y install mariadb-server mariadb-client

All dependencies are installed automatically. To confirm the version of installed package use the commands:

$ mariadb -V
mariadb from 11.0.1-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using  EditLine wrapper

Step 4: Secure MariaDB installation

mariadb-secure-installation is a command-line tool used to secure the MariaDB installation by performing various security-related tasks. You need to run the command as the root user or with sudo privileges.

sudo mariadb-secure-installation

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 haven’t set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation.

Switch to unix_socket authentication [Y/n]
Enabled successfully!
Reloading privilege tables..
 ... Success!

Agree to set new password.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

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!

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!

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!

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

If you’ve completed all of the above steps, your MariaDB installation should now be secure.

Step 5: Test MariaDB installation

Connect to database server using mariadb line tool.

mariadb -u root -p

Confirm the connection is successful.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 11.0.1-MariaDB-1:11.0.1+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

To check version run:

MariaDB [(none)]> SELECT VERSION();
+---------------------------------------+
| VERSION()                             |
+---------------------------------------+
| 11.0.1-MariaDB-1:11.0.1+maria~ubu2204 |
+---------------------------------------+
1 row in set (0.001 sec)

To create a database in MariaDB, you can use the following SQL command:

CREATE DATABASE database_name;

See example below.

CREATE DATABASE sample_db;

Next we create a user and grant privileges using the following SQL commands:

CREATE USER 'sample_db_user'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON sample_db.* TO 'sample_db_user'@'localhost';

To add sample data to your new database, you can use the INSERT command. Here’s an example:

USE sample_db;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50),
    email VARCHAR(50)
);

INSERT INTO users (name, email) VALUES
    ('John Doe', '[email protected]'),
    ('Jane Smith', '[email protected]'),
    ('Bob Johnson', '[email protected]');

This creates a new table called users in the local sample_db database we created earlier, with three sample records inserted into the table. The table structure can be modified with the sample data as needed to suit your specific needs. To clean drop database and user.

drop database sample_db;
drop user sample_db_user@localhost;

We hope this article was helpful and we would to thank you for reading through. Follow us in our social media accounts to learn more about our work and get updates for new articles we publish.

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments