How to Install and Secure MariaDB on Ubuntu 24.04

MariaDB is a popular, open-source relational database management system, widely recognized as a drop-in replacement for MySQL. It offers robust performance, strong security features, and a flexible structure, making it suitable for a variety of applications. In this tutorial, we’ll walk through the process of installing MariaDB on Ubuntu 24.04, a recent and stable release of one of the most popular Linux distributions. Whether you’re setting up a web server, a cloud application, or just experimenting with database management, this guide will help you get MariaDB up and running on your Ubuntu system.

In this tutorial you will learn:

  • How to update package indexes on your system
  • Steps to install MariaDB
  • How to check the status and enable MariaDB to start on boot
  • Securing your MariaDB installation
How to Install and secure MariaDB on Ubuntu 24.04
How to Install and secure MariaDB on Ubuntu 24.04

Installing MariaDB on Ubuntu 24.04

Follow these steps to install and configure MariaDB on your Ubuntu 24.04 system. These steps will ensure that your MariaDB installation is up-to-date and secured against unauthorized access.

  1. Update Package Indexes: Before installing any new package, it’s important to update your system’s package indexes. This ensures that you are installing the latest versions of packages and their dependencies.
    $ sudo apt update

    This command updates the list of available packages and their versions, but it does not install or upgrade any packages.

  2. Install MariaDB: Once the package lists are updated, you can proceed with the installation of MariaDB.
    $ sudo apt install mariadb-server

    This command will download and install MariaDB and its required dependencies. During the installation, you may be asked to confirm the download and installation; press ‘Y’ to continue.

  3. Check Status and Enable MariaDB: After installation, it’s a good practice to check the status of the MariaDB service. Additionally, you should enable MariaDB to start automatically upon system boot.
    $ sudo systemctl status mariadb
    Check MariaDB status
    Check MariaDB status

    This command checks the status of the MariaDB service. You should see an output indicating that the service is active and running.

    $ sudo systemctl enable mariadb

    This command enables MariaDB to start automatically when your system boots up.

  4. Secure the Installation: The ‘mysql_secure_installation’ script is a critical step in securing your MariaDB installation. When you run this script, it will guide you through several options to enhance the security of your MariaDB server. You’ll be given choices to set or skip the root password if it’s already set, an option to switch to unix_socket authentication, and prompts to remove anonymous users and disallow root login remotely, which are recommended for increased security.

    Secured Mariadb the Installation
    Secured Mariadb the Installation

    Additionally, it will offer the choice to remove the ‘test’ database, which is advisable in a production environment. Finally, you’ll be prompted to reload privilege tables to apply changes immediately. Carefully consider each option based on your security needs and server environment.

    $ sudo mysql_secure_installation

    Securing your MariaDB installation with the mysql_secure_installation script involves several key decisions. First, it’s crucial to set a root password if you haven’t already, as it ensures basic security for database access. In cases where MariaDB root user aligns with the system’s root user, switching to unix_socket authentication is recommended for enhanced security, although this may be skipped based on your specific remote access requirements. It’s always advisable to remove anonymous users to prevent unauthorized database access.

    Similarly, disallowing root login remotely is a critical step in mitigating brute-force attacks, and you should consider this unless remote administration is absolutely necessary. Removing the ‘test’ database is also recommended, as it is accessible by default and poses a security risk. Lastly, make sure to reload privilege tables after making these changes to ensure they are immediately effective. These steps are pivotal in safeguarding your MariaDB installation against common security threats.


By following these steps, you have successfully installed and secured MariaDB on your Ubuntu 24.04 system. This setup provides a solid foundation for your database needs, whether for development, testing, or production use. Remember to regularly update your system and MariaDB to get the latest features and security updates. Enjoy working with MariaDB!

FAQs: How to Install and Secure MariaDB on Ubuntu 24.04

  1. What is MariaDB?

    MariaDB is an open-source relational database management system, a fork of MySQL, known for its performance, reliability, and ease of use.

  2. Is MariaDB compatible with MySQL?

    Yes, MariaDB is highly compatible with MySQL, meaning it can directly replace MySQL in most cases.

  3. How do I install MariaDB on Ubuntu 24.04?

    Use the command sudo apt install mariadb-server to install MariaDB on Ubuntu 24.04.

  4. How can I check if MariaDB is successfully installed?

    After installation, run sudo systemctl status mariadb to check if the service is active and running.

  5. Why should I run the ‘mysql_secure_installation’ script?

    This script is crucial for removing default settings that are insecure, like anonymous users and remote root login.

  6. Should I set a root password during MariaDB installation?

    Yes, setting a strong root password is recommended for securing your database.

  7. What is unix_socket authentication in MariaDB?

    Unix_socket authentication allows login as the MariaDB root user only when the system user is also root, enhancing security.

  8. How do I remove anonymous users in MariaDB?

    This can be done through the ‘mysql_secure_installation’ script by answering ‘Y’ when prompted.

  9. Is it safe to disallow root login remotely?

    Yes, disallowing root login remotely is recommended for security purposes, unless remote administration is required.

  10. Why should I remove the ‘test’ database in MariaDB?

    The ‘test’ database is accessible by default and should be removed to prevent unauthorized access.

  11. How do I enable MariaDB to start on boot?

    Use the command sudo systemctl enable mariadb to enable MariaDB to start automatically on boot.

  12. Can I encrypt data in MariaDB?

    Yes, MariaDB supports data encryption at both the column level and through Transparent Data Encryption (TDE).

  13. How do I update MariaDB to the latest version?

    Regularly run sudo apt update and sudo apt upgrade to keep MariaDB updated.

  14. How can I back up my MariaDB database?

    Use tools like mysqldump or MariaDB backup utilities to regularly back up your database.

  15. Where can I find more information about MariaDB?

    Visit the official MariaDB website and documentation for comprehensive information and resources.