How to install MariaDB on Debian 12

Introduction
MariaDB is a popular open-source relational database management system that is widely used for its performance, stability, and compatibility with MySQL. Whether you are setting up a new server or migrating from another database system, installing MariaDB on Debian 12 is a straightforward process. This guide will walk you through the necessary steps to get MariaDB up and running on your Debian 12 system. From updating your system and installing the MariaDB server to securing the installation and configuring it for your specific needs, this tutorial covers everything you need to ensure a smooth and secure setup. Let's get started!
Update the system:
sudo apt update && sudo apt upgrade -yInstall MariaDB Server Installation: Run the security script to improve the security of your MariaDB installation.
sudo apt install mariadb-server -ySecure the MariaDB Installation: Run the security script to improve the security of your MariaDB installation.
sudo mysql_secure_installationFollow the prompts to set the root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.
Start and Enable MariaDB Service: Ensure that MariaDB is running and will start on boot.
sudo systemctl start mariadb sudo systemctl enable mariadbConfigure MariaDB (Optional): if you need to configure MariaDB for remote access or adjust other settings, open the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnfFor remote access, find the line
bind-addressand change it to:bind-address = 0.0.0.0Save and close the file.
Create a MariaDB User: Create a new user and grant privileges:
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword'; GRANT ALL ON . TO 'myuser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES; EXIT;Restart MariaDB Service: Restart the MariaDB service to apply any configuration changes.
sudo systemctl restart mariadbConclusion
Installing MariaDB on Debian 12 is a straightforward process that involves updating your system, installing the MariaDB server, securing the installation, and configuring it to meet your needs. By following these steps, you ensure that your MariaDB server is not only up and running but also secure and optimized for your specific requirements. Whether you need to set up a new user, enable remote access, or adjust other settings, this guide provides a comprehensive approach to getting MariaDB ready for production use.