How to Install MariaDB On Debian 12


Here’s a bash script to automate the installation of MariaDB Server on Debian. The script handles both installation from the default Debian repository and from the official MariaDB repository if a newer version is required.

Bash Script to install MariaDB on Linux

#!/bin/bash

# Bash script to install MariaDB Server on Debian

# Function to install MariaDB from the default Debian repository
install_from_debian_repo() {
    echo "Updating package list..."
    sudo apt update -y

    echo "Installing MariaDB Server and Client from Debian repository..."
    sudo apt install -y mariadb-server mariadb-client

    echo "Starting and enabling MariaDB service..."
    sudo systemctl start mariadb
    sudo systemctl enable mariadb

    echo "Securing MariaDB installation..."
    sudo mysql_secure_installation

    echo "MariaDB installed from Debian repository successfully!"
}

# Function to install MariaDB from the official MariaDB repository
install_from_mariadb_repo() {
    echo "Downloading MariaDB repository setup script..."
    wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup -O mariadb_repo_setup

    echo "Running repository setup script..."
    sudo bash mariadb_repo_setup

    echo "Updating package list..."
    sudo apt update -y

    echo "Installing MariaDB Server and Client from MariaDB repository..."
    sudo apt install -y mariadb-server mariadb-client

    echo "Starting and enabling MariaDB service..."
    sudo systemctl start mariadb
    sudo systemctl enable mariadb

    echo "Securing MariaDB installation..."
    sudo mysql_secure_installation

    echo "MariaDB installed from official MariaDB repository successfully!"
}

# Main script
echo "Select installation method:"
echo "1) Install MariaDB from Debian repository (default)"
echo "2) Install the latest MariaDB from the official MariaDB repository"
read -p "Enter your choice [1-2]: " choice

case $choice in
    1)
        install_from_debian_repo
        ;;
    2)
        install_from_mariadb_repo
        ;;
    *)
        echo "Invalid choice. Exiting."
        exit 1
        ;;
esac

How to Use the Script

  1. Save the script to a file, e.g., install_mariadb.sh.
  2. Make the script executable: chmod +x install_mariadb.sh
  3. Run the script: sudo ./install_mariadb.sh
  4. Follow the on-screen prompts to select the installation method (Debian repo or official MariaDB repo).

What the Script Does

  1. Option 1: Installs MariaDB using Debian’s default package repository.
  2. Option 2: Sets up the MariaDB repository to install the latest version.

This script automates the installation process and ensures the MariaDB service is properly configured.

Remove MariaDB from Linux

https://youtu.be/1F2YQqyASf8

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.