How to Upgrade MariaDB Server to a Newer Version in Ubuntu
Posted in: Database, Linux, MariaDB, MySQL, Security, Ubuntu

How to Upgrade MariaDB Server to a Newer Version in Ubuntu

In this guide, you will learn how to safely upgrade the MariaDB database server to a newer version in the Ubuntu Linux distribution. Also, you will know how to check current MariaDB packages and remove the older version after upgrading the MariaDB server.

Create Hosting Server Backup

First of all, it’s important to create a full backup of your server or website in order to restore it in case something goes wrong. You can use snapshots or any of your preferred methods to create a full backup of your hosting server. After creating the backup, you can proceed with the upgradation process of the MariaDB server by following the steps below.

Check MariaDB Version and Repository Sources

To be able to update MariaDB, log in to your SSH terminal with a user having sudo privilege so we can run commands.

First, you can check the current version of MariaDB with this command:

> mariadb --version

You can also use this command to check the version of MariaDB:

> dpkg -l | grep mariadb

The above command lists all installed software packages and filters for those that contain “mariadb” in their name. This helps to identify any installed MariaDB packages. Also, it mentions the version of the installed package.

Next, run the following command to check the repository sources. Here, check the source list to identify if there’s any source repository with MariaDB listed there. Most commonly, it would be something like “/etc/apt/sources.list.d/mariadb.list”. If it already exists, then we can change it to a new version. And, if it doesn’t exist then we can add it with a new version.

> grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*

After, we would need to add MariaDB with a new version in the repository source if it doesn’t exist already. Also, we may just need to change the version of the MariaDB server if it already exists in the source repository list.

Add MariaDB with New Version in Repository Source

Suppose your current version of MariaDB is 10.3 and you want to upgrade it to version 10.6.

If you already see an existing package in the repository source with a name like “mariadb.list” using the previous “grep” command and you see its current version as 10.3. Then, to change it from version 10.3 to 10.6, you would use the following command:

> sudo sed -i 's/10.3/10.6/' /etc/apt/sources.list.d/mariadb.list

In case you can’t find any repository source with “mariadb” in it, then to add it for version 10.6, you can run the command:

> sudo curl -LsS | sudo bash -s -- --mariadb-server-version="mariadb-10.6"

The above command would add a new repository source for any relevant MariaDB 10.6 packages that we can install or upgrade to. You can verify the repository source list again to check if it now adds “mariadb.list” to the source list using the command:

> grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*

Upgrade MariaDB to New Specified Version

Once, you are sure that the “mariadb.list” exists in the repository source, then you can run the following command to update the package list by fetching the latest information about available software and updates from the software repositories.

> sudo apt update

Now, we are ready to perform the actual upgrade of the MariaDB database server.

First, we need to stop the running “mariadb” service using the command:

> sudo systemctl stop mariadb

Next, run the following command to do the upgrade, it will specify which packages it would add, change, or remove after the upgrade, you can confirm with “Y”:

> sudo apt install --only-upgrade mariadb-server

After, run the command to remove packages that it won’t need anymore and confirm:

> sudo apt autoremove

Once the upgradation process is finished, we would need to reload the daemon process. This ensures that the system recognizes and applies any changes in the MariaDB service configuration. It allows the upgraded database to function correctly with the newly updated settings without needing a full system restart.

> sudo systemctl daemon-reload

Also, you can start the “mariadb” service with this command:

> sudo systemctl start mariadb

Finally, we can run the “mariadb-upgrade” command to ensure that your MariaDB database functions properly after an upgrade by making necessary adjustments and fixing any compatibility issues that might arise.

It upgrades system tables, performance schema, INFORMATION_SCHEMA, and sys schema. Also, it examines user schemas to ensure compatibility and take advantage of new features.

> sudo mariadb-upgrade

Note that you may also run “mysql_upgrade” in place of “mariadb-upgrade” in case it doesn’t work:

> sudo mysql_upgrade

In case, it throws an error “Access denied for user ‘root’@’localhost'”, then you can provide the MariaDB root user password in the command as follows:

> sudo mariadb-upgrade -u root -p

Or, by using “mysql_upgrade”:

> sudo mysql_upgrade -u root -p

You may also force the check for any incompatibilities with the upgraded MariaDB server with any one of these commands:

> sudo mariadb-upgrade --force
> sudo mysql_upgrade --force
> sudo mariadb-upgrade -u root -p --force
> sudo mysql_upgrade -u root -p --force

Confirm the New Version of MariaDB

Now, to confirm the new version, you can use the command to list installed MariaDB packages with version information:

> dpkg -l | grep mariadb

Remove the Old Version of MariaDB and Cleanup

You may see older packages of MariaDB when you run the above “dpkg” command. You can remove those old packages by using their names as follows:

> sudo apt purge mariadb-server-10.3 mariadb-client-10.3

Again, you can confirm the MariaDB packages and the older packages should not be there now.

> sudo dpkg -l | grep mariadb

So, now you have the newer version of MariaDB without any residual packages.

In conclusion, upgrading MariaDB to a newer version brings performance improvements, security enhancements, new features, bug fixes, and long-term support. It’s always crucial to create a full backup of your hosting server before doing upgrades like this. There are several steps to follow when you want to upgrade MariaDB to the latest version.

We also have a step-by-step, easy-to-follow guide on how to reset MySQL root password and this guide works for the MariaDB database server as well.

Back to Top