Edited 4 weeks ago by ExtremeHow Editorial Team
DebianMariaDBDatabaseServer SetupSQLLinuxOpen SourceSystem AdministrationCLISoftware
This content is available in 7 different language
MariaDB is a popular open-source relational database management system that is a part of MySQL. It is widely used due to its better performance, security features, and compatibility with MySQL. In this long tutorial, we will learn how to install and configure MariaDB on a Debian-based system. The following topics will be covered:
MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system. It is intended to remain free under the GNU General Public License (GPL). Being essentially a MySQL fork, MariaDB maintains its compatibility with MySQL and adds new features, improves performance, and fixes bugs. It is a robust, reliable, and completely open-source database technology that attracts a large user community.
Before we begin the installation and configuration of MariaDB on Debian, there are a few prerequisites that need to be taken care of:
Make sure all the packages on your system are updated. Run the following command:
sudo apt update && sudo apt upgrade -y
The installation process of MariaDB on Debian can be completed using the APT package management tool. Here is how you can install it:
MariaDB packages are built into the official repositories for most Linux distributions. However, to get the latest version, or to have more control over which version to install, it is recommended to add the official MariaDB repository.
Open the MariaDB repository configuration page, and find the repository setup for your Debian version here: https://downloads.mariadb.org/mariadb/repositories/
Depending on your Debian system version, run the command to add the repository. For example, for Debian 10:
sudo apt install software-properties-common dirmngr -y sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 sudo add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.5/debian buster main'
After adding the repository, update your package database:
sudo apt update
Install the MariaDB server and client using the following commands:
sudo apt install mariadb-server mariadb-client -y
The MariaDB service will start automatically after installation. Verify it as follows:
sudo systemctl status mariadb
Once MariaDB is installed, some basic configuration steps are recommended.
MariaDB comes with a built-in security script that makes it easy to tweak security settings. Run the following command:
sudo mysql_secure_installation
This script will modify the less secure default options. It will prompt you to set the root password, remove anonymous users, disallow remote root logins, and remove the test database. Answer yes to each step unless you have a specific reason to keep a particular setting.
To interact with MariaDB, enter the MariaDB shell by running the following:
sudo mariadb
You will see the MariaDB shell interface where you can run SQL queries and commands.
Even though we run secure installation scripts, it is always good to understand and ensure additional security settings that can be adjusted manually.
Open the MariaDB server configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Within this file, you can configure many important security settings, including file permissions, port and socket setup, etc.
bind-address = 127.0.0.1
[mysqld]
section and modify the port:port = 3306
Save and exit the file after making the changes. Restart the MariaDB service to apply the modifications:
sudo systemctl restart mariadb
To start using MariaDB for your development or production, you need a database and a user configured with specific privileges. Follow these steps to set it up:
Login to the MariaDB shell using the following command:
sudo mariadb
To create a new database, run the following command, replacing my_database
with your desired database name:
CREATE DATABASE my_database;
Ensure creation by listing the available databases:
SHOW DATABASES;
Create a new user to handle this database. Use the command below and replace my_user
and password123
with your preferred username and password:
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'password123';
Grant the necessary privileges to your newly created user. The command below grants all privileges on the database to the user for localhost:
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
Flush the privileges to make sure the new user and privilege settings are loaded properly:
FLUSH PRIVILEGES;
Exit the MariaDB shell by typing the following:
EXIT;
By following the steps outlined in this comprehensive guide, you have successfully installed and configured MariaDB on your Debian system. You have also secured the installation, created the database, and set up a new user with appropriate privileges. MariaDB is now ready for your use, whether as a backend for personal projects, a web server, or applications. With regular updates and community support, MariaDB remains a valuable addition to any data-driven suite.
Continue to stay informed about the latest updates and practices in database management to get the most out of your MariaDB setup.
If you find anything wrong with the article content, you can