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
- Save the script to a file, e.g.,
install_mariadb.sh
. - Make the script executable:
chmod +x install_mariadb.sh
- Run the script:
sudo ./install_mariadb.sh
- Follow the on-screen prompts to select the installation method (Debian repo or official MariaDB repo).
What the Script Does
- Option 1: Installs MariaDB using Debian’s default package repository.
- 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
Contents
show