Menu

How to Install MariaDB on Debian 10 (Legacy Guide)

Legacy MariaDB installation guide for Debian 10 Buster. Debian LTS ended on June 30, 2024; use Debian 13 for a new installation.

Posted on By Updated on
On this page

Support status: Debian 10 Buster LTS ended on June 30, 2024, and the Debian project no longer provides security updates for it. Third-party Extended LTS may cover a subset of packages. Keep this guide for existing legacy systems; for a new server, see our MariaDB 12.3 guide for Debian 13. See Debian’s release status and Debian 10’s LTS end-of-life notice.

Prerequisites

Before you begin, ensure you have the following:

  1. A Debian 10 system with root or sudo access.
  2. An SSH client to connect to your server.
  3. A stable internet connection.

Step 1: Update Your System

Refresh package metadata and install only packages available from your configured sources. This does not restore Debian 10 security maintenance; archived sources or a third-party Extended LTS service may be required:

sudo apt update
sudo apt upgrade

This command will refresh your system’s package repository and upgrade installed packages.

Step 2: Install MariaDB

Debian 10 includes MariaDB in its default repositories, making installation simple. Use the following command to install MariaDB:

sudo apt install mariadb-server

During the installation, you’ll be prompted to confirm the package installation. Type ‘y’ and press Enter.

Step 3: Start and Enable MariaDB

After installation, start the MariaDB service and enable it to start at boot with the following commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

You can verify that MariaDB is running with this command:

sudo systemctl status mariadb

Step 4: Secure Your MariaDB Installation

MariaDB comes with a script that helps you secure your database installation. Run the following command:

sudo mysql_secure_installation

You’ll be prompted to set a root password, remove anonymous users, disallow root login remotely, and remove the test database. Follow the prompts and answer ‘Y’ or ‘N’ as needed.

Step 5: Log In to MariaDB

Now that your MariaDB installation is secure, you can log in to the database server using the following command:

sudo mysql -u root -p

Enter the root password you set during the installation when prompted.

Step 6: Create a New Database and User

To create a new database and user, follow these steps:

  1. Log in to MariaDB as the root user.

  2. Create a new database (replace mydatabase with your preferred name):

    CREATE DATABASE mydatabase;
    
  3. Create a runtime application account with row-level privileges. Use a separate migration account for schema changes; replace myuser and the password placeholder with the intended account name and a unique secret from a password manager:

    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'replace-with-a-unique-secret';
    GRANT SELECT, INSERT, UPDATE, DELETE ON mydatabase.* TO 'myuser'@'localhost';
    
  4. Exit the MariaDB prompt:

    exit;
    

Step 7: Test Your MariaDB Installation

You can test your new database and user by logging in with the created credentials:

mysql -u myuser -p

Enter the password when prompted, and you should now have access to the database you created.

Conclusion

You’ve successfully installed MariaDB on your Debian 10 system, secured the installation, and created a new database and user. MariaDB is a powerful and reliable database system that can serve as the foundation for various web applications and services. You are now ready to build and manage your databases with MariaDB on Debian 10.