# 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!

1. **Update the system:**
    
    ```apache
    sudo apt update && sudo apt upgrade -y
    ```
    
2. **Install MariaDB Server Installation:** Run the security script to improve the security of your MariaDB installation.
    
    ```apache
    sudo apt install mariadb-server -y
    ```
    
3. **Secure the MariaDB Installation:** Run the security script to improve the security of your MariaDB installation.
    
    ```apache
    sudo mysql_secure_installation
    ```
    
    Follow the prompts to set the root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.
    
4. **Start and Enable MariaDB Service:** Ensure that MariaDB is running and will start on boot.
    
    ```apache
    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    ```
    
5. **Configure MariaDB (Optional): i**f you need to configure MariaDB for remote access or adjust other settings, open the MariaDB configuration file:
    
    ```apache
    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
    ```
    
    For remote access, find the line `bind-address` and change it to:
    
    ```apache
    bind-address = 0.0.0.0
    ```
    
    Save and close the file.
    
6. **Create a MariaDB User:** Create a new user and grant privileges:
    
    ```apache
    CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';
    GRANT ALL ON . TO 'myuser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    EXIT;
    ```
    
7. **Restart MariaDB Service:** Restart the MariaDB service to apply any configuration changes.
    
    ```apache
    sudo systemctl restart mariadb
    ```
    
    ## **Conclusion**
    
    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.
