Debian 11: Upgrade Mariadb 10.5 to 10.11

Post Reply
shahidirfan
Posts: 23
Joined: Sat Sep 05, 2020 11:28 am
Been thanked: 2 times

Hi,

This is a bash script to upgrade MariaDB from 10.5 to 10.11 on Debian 11. It's always best to back up and keep a snapshot of your VPS before upgrading to prevent any issues.

Code: Select all

#!/bin/bash

# MariaDB Upgrade Script: 10.5 to 10.11 for Debian with MyVestaCP
# IMPORTANT: Backup your databases and configurations before running this script!

set -e

# Function to check if a command was successful
check_command() {
    if [ $? -ne 0 ]; then
        echo "Error: $1"
        exit 1
    fi
}

# Check if running as root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 
   exit 1
fi

# Stop MariaDB and MyVestaCP services
systemctl stop mariadb
systemctl stop vesta

# Backup current MariaDB configuration
cp -a /etc/mysql /etc/mysql.bak
echo "MariaDB configuration backed up to /etc/mysql.bak"

# Update package list
apt update
check_command "Failed to update package list"

# Install MariaDB 10.11 repository
apt install -y software-properties-common
apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
add-apt-repository 'deb [arch=amd64] http://mirror.mva-n.net/mariadb/repo/10.11/debian bullseye main'

# Update package list again
apt update
check_command "Failed to update package list after adding MariaDB repository"

# Upgrade MariaDB
apt install -y mariadb-server
check_command "Failed to install MariaDB 10.11"

# Run MariaDB upgrade script
mysql_upgrade
check_command "mysql_upgrade failed"

# Restart MariaDB
systemctl start mariadb
check_command "Failed to start MariaDB service"

# Update MyVestaCP configuration
sed -i 's/10.5/10.11/g' /usr/local/vesta/conf/mysql.conf
check_command "Failed to update MyVestaCP MySQL configuration"

# Start MyVestaCP
systemctl start vesta
check_command "Failed to start MyVestaCP service"

echo "MariaDB has been successfully upgraded to version 10.11"
echo "Please verify your databases and applications are working correctly"

Tags:
Post Reply