How to Install MariaDB on Debian 11

MariaDB is a robust, scalable, and reliable SQL server that has over 4 years of active development. It is an enhanced, drop-in replacement for the MySQL relational database management system - but with more features, new storage engines, fewer bugs, and better performance.

The original developers of MySQL founded MariaDB in 2009 as a fork from the now-defunct project after concerns about that Oracle's acquisition of MySQL.

In 2010, Sun Microsystems (which had previously been acquired by Oracle Corp.) divested its open-source business into a new subsidiary called "Oracle America", which was to be led by Thomas Kurian—the former head of Sun's Solaris unit.

"MariaDB" is named after co-founder Michael Widenius' daughter, Maria.

MariaDB is mostly written in C/C++, with low-level parts written in assembly language for optimization, and some key parts of the server like the query parser still written in MySQL's "de facto" standard dialect of SQL, which allows the use of procedural languages like Perl and Python to access de-normalized databases.

Generally speaking, MariaDB shows improved speed and efficiency over MySQL, but it's advisable to do a trial run for your specific site before making the switch from MySQL.

In one test done by W3Tech, MariaDB was found to be 30% faster than MySQL when dealing with both small and large data sets. In another test, MariaDB showed a 20% improvement in speed compared with MySQL when working with 1 GB of data. When the amount of data was increased to 10 GB, MariaDB proved a whopping 80% faster in comparison to MySQL.

Prerequisite

In order to install MariaDB on Debian 11, you need to have:

  • A server running Debian 11.
  • Root access to the server.
  • Hardware requirements: 1 CPU core is more than enough for a database server. 512MB of RAM and 1 GB of hard-disk is enough for minimal data.

Updating the System

System updates are important to do on your computer. Often, a Linux update will introduce new features and improvements or resolve a bug that has been reported by a user. It's a good idea to apply a system update as soon as one becomes available so you can take advantage of any new security patches and other improvements the software might have.

Run the following command to update your system.

sudo apt-get update && sudo apt-get upgrade -y

Once the system update is complete, run the command below to install the required packages.

sudo apt-get install software-properties-common dirmngr gnupg2 -y
sudo apt-get install apt-transport-https wget curl -y

Installing MariaDB on Debian 11

As usual, we can install MariaDB directly from the repository. We will be using the default package manager for Debian 11 to install MariaDB as this is the most recommended method. However, you might not have access to the latest version of MariaDB if it's not part of the official repositories.

Run the command below to show the available repositories for MariaDB.

sudo apt search mariadb

The output shows the official Debian repository as shown below. You will see many packages under the MariaDB umbrella. Some are for administration tools, while others are components of the database software itself.

Installing MariaDB on Debian 11

Run the following command to install MariaDB on Debian 11.

sudo apt-get install mariadb-server -y

Run the mariadb --version command to check if MariaDB is correctly installed. When you issue the mariadb --version command, the output should be as shown below. Note that the version numbers might be different.

Installing MariaDB on Debian 11

To start, stop, restart the MariaDB database server, use the following commands.

sudo systemctl start mariadb
sudo systemctl stop mariadb
sudo systemctl restart mariadb

To enable MariaDB to automatically start when your system boots, run the following command.

sudo systemctl enable mariadb

MariaDB should be up and running at this point. You can check if it's running by executing the following command.

sudo systemctl status mariadb

The command returns the service status and its PID. The value for the PID field should match the process ID when executing the systemctl start mariadb command above.

Sample output: 

Installing MariaDB on Debian 11

For double-checking, you can use the mysqladmin tool to ensure MariaDB is up and running. mysqladmin is a client tool for communicating with the MariaDB server and letting you perform administrative tasks. Such as checking the server's configuration, managing databases, managing users, and much more.

For example, run the mysqladmin version command to show the MariaDB server version, server's uptime, and other useful information.

sudo mysqladmin version

You will get an output similar to the screenshot below.

Installing MariaDB on Debian 11

Securing MariaDB

Now that you have installed, started, and have a MariaDB server running. It's time to secure your installation. When you first install MariaDB, the default settings are weak, and you should take prompt actions to secure your installation.

First, let's run the mysql_secure_installation script, which is located in the /usr/bin directory. The mysql_secure_installation script is a method of helping to secure the MariaDB database server.

A MariaDB system administrator can run the script at installation time or when upgrading to a new version. The script creates a new, random root password for the MariaDB database, removes anonymous-user accounts, and limits access to the database server based on hostname.

sudo /usr/bin/mysql_secure_installation

You will be prompted to enter the MariaDB root password. Just leave the root password empty, and hit Enter. For the rest, just enter Y and hit Enter.

Sample output:

Installing MariaDB on Debian 11

Accessing MariaDB

Run the following command to log in to the MariaDB Server. After you have done the mysql_secure_installation script, you need to provide your root password when logging in to the MariaDB server. Otherwise, you will get an Access denied error.

We will use the -p option with the mysql command to tell it to prompt for the password.

mysql -u root -p

You will be prompted to enter the MariaDB root password after which you can access your MariaDB server.

Accessing MariaDB

You will be prompted for your MariaDB root password. Enter your root password and hit the Enter key. You will then be logged into the MariaDB shell. Your shell will change to MariaDB> The prompt at the bottom shows you are inside a MariaDB shell. This is where you can enter SQL statements to manage your MariaDB server.

The output will also show the MariaDB version used. This is useful for support engineers when asking questions about particular bugs or errors.

Sample output:

Accessing MariaDB

Finally, to exit out of the MariaDB shell, type the following command and hit Enter.

quit;

or

exit;

Sample output: 

Accessing MariaDB

Creating a New Administrative User

Now that you have logged into the MariaDB prompt, go ahead and create a new administrative user. This will be the first user to access your MariaDB server after installation.

Run the following statement to create a new user with a username of howtoforge, and with a password of password123. Feel free to change the username and password to suit your needs.

GRANT ALL ON *.* TO 'howtoforge'@'localhost' IDENTIFIED BY 'password123' WITH GRANT OPTION;

Next, run the statement below to reload the privilege table. This will allow any new or updated privileges you have just added to take effect.

FLUSH PRIVILEGES;

To test the new user you have created, exit your current MariaDB shell, and run the following statement to log in as your newly-created user.

The prompt will change to indicate the new users login name howtoforge.

exit;
mysql -u howtoforge -p

Enter password123 when prompted for password, then hit Enter. You are now logged into the MariaDB server as administrative user howtoforge.

Sample output: 

Creating a New Administrative User

Conclusion

In this tutorial, you have learned how to install MariaDB database server on Debian 11. You have also learned how to secure your installation through the mysql_secure_installation script and create a new administrative user.

You now have a fully functional MariaDB server that can be used as a replacement for MySQL. Enjoy using MariaDB!

Share this page:

Suggested articles

0 Comment(s)

Add comment