Upgrade to MariaDB 10.6 on Ubuntu 20.04

This article is not about just upgrading but also how to backup and restore your databases in the process. Ubuntu 20.04 has MariaDB 10.3 as default package in the repository. Upgrading is not difficult but when it comes to data, it is always best to avoid such things unless necessary. Today I am going to show you how to upgrade to MariaDB 10.6 on Ubuntu 20.04 and backup-restore the databases in the process.

What we will cover:

  • Backup databases
  • Upgrade to MariaDB 10.6
  • Restore databases

I want to clear one point here, even it is not really required to backup your data but as I always say “Backup your data even if you don’t need it”. That’s because when upgrade to another version the databases dir is still intact and not deleted in this process.

If you would like to know what versions are currently available in the repositories.

apt-cache show mariadb-server | grep Version
mariadb-versions

Install some basic and required packages.

sudo apt install mariadb-backup wget curl

Backup databases

I am going to show you two ways to backup your databases.

1- mysqldump

I have already wrote a detail article on how to backup databases with mysqldump. This is useful if you have one or two databases. But if you have a large set of databases to manage, jump to step 2.

2- mariabackup

This part takes care of all the databases and data in one command.

sudo mariabackup --backup \
      --user=root \
      --password= \
      --target-dir=/home/mian/mariadb_full_backup

Change --user, --password to your actual database admin username/password. --target-dir is where the data will be store. Change this path accordingly.

Now if you would like to prepare this data backup for restoring after upgrade just run the following command.

sudo mariabackup --prepare \
	  --use-memory=34359738368 \
      --target-dir=/home/mian/mariadb_full_backup

Check the restore step 2 below for how to restore them.

Upgrade to MariaDB 10.6

Check the status of the database and stop it if it’s running.

sudo systemctl status mariadb
sudo systemctl stop mariadb

Remove all the current packages.

sudo apt remove mariadb-* galera-3

Download the bash script.

wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

echo "b9e90cde27affc2a44f9fc60e302ccfcacf71f4ae02071f30d570e6048c28597 mariadb_repo_setup" \
    | sha256sum -c -

Make the script executable.

chmod +x mariadb_repo_setup

Run the script.

sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-10.6"

Install the updated version now.

sudo apt update
sudo apt install mariadb-server mariadb-backup

After installation, start the database server.

sudo systemctl start mariadb
sudo systemctl enable mariadb

Check it’s version.

mariadb -V

This is pretty much it for the upgrading process.

Restore databases

At this point you have all the databases and everything there, but just in case you would like to restore if you had a clean install.

1- mysql

Same as backup, you can find the restore part also in this article. It uses mysql tool to restore databases.

2- mariabackup

If you have backup-ed the databases using method 2 above. Use this step to restore them.

Stop the database server.

sudo systemctl stop mariadb

Move the current mysql data dir.

sudo mv /var/lib/mysql /var/lib/mysql-backup 

Create a new dir.

sudo mkdir /var/lib/mysql

Restore the data to this newly created dir.

sudo mariabackup --copy-back --target-dir=/home/mian/mariadb_full_backup

Change the ownership.

sudo chown -R mysql:mysql /var/lib/mysql

Start the database server now.

sudo systemctl start mariadb

Leave a Reply

Your email address will not be published.