Upgrading MariaDB manually

Note: These instructions seem to be out of date/incomplete. Before we update the official doc, it would be good to have extra input. Please see the comments below for more information and post any issues/changes that you discover.


MariaDB 10.1 is depreciating in the upcoming weeks so Cyberpanel 2.0.3 will come with MariDB 10.5. New installation will be automatically based on that version and older version will be upgraded.

If you don’t see the latest version after upgrade or mariadb doesn’t work for you any more, here are the steps to fix that

  1. Make sure that the repo has been updated

cat /etc/yum.repos.d/mariadb.repo

If the output has 10.5 in the string you are okay to continue, if not, please edit the file and update it to 10.5

  1. Backup MariaDB’s configuration files

Run the following commands to backup the current configuration

cp /etc/my.cnf /etc/my.cnf.bak 
mkdir /etc/cnfbackup 
cp -R /etc/my.cnf.d/ /etc/cnfbackup/
  1. Remove the current version

Run these commands to remove MariaDB
For Centos

yum remove MariaDB-server MariaDB-client galera MariaDB-devel MariaDB-shared -y

For Ubuntu

apt remove MariaDB-server MariaDB-client galera MariaDB-devel MariaDB-shared -y

  1. Install MariaDB 10.5

For Centos

yum --enablerepo=mariadb -y install MariaDB-server MariaDB-client MariaDB-devel MariaDB-shared -y

For Ubuntu

apt install MariaDB-server MariaDB-client MariaDB-devel MariaDB-shared -y

  1. Restore the backed up files
cp -f /etc/my.cnf.bak /etc/my.cnf 
rm -rf /etc/my.cnf.d/ 
mv /etc/cnfbackup/my.cnf.d /etc/
  1. Enable and start MariaDB 10.5
systemctl enable mariadb
systemctl start mariadb
1 Like

@usmannasir As I detailed in this thread on the facebook group, MariaDB 10.3 is still installed with all versions of linux. The problem is that the distros haven’t updated their packages beyond 10.3, so the instructions you’ve provided here don’t help. You need to change the packages manually.

I think have finally properly upgraded to MariaDB v10.6 on Ubuntu 20.04. Here is what I did. The process should be similar for other OSs, but please be careful and post any variations that you discover below.

Note: there’s a lot of extra steps included here just to be extra thorough. For instance, it isn’t absolutely necessary to check the packages installed/uninstalled, check status of mariadb etc…

1. Review Official MariaDB Instructions

2. Backup

I didn’t take any backups, but the method written above by Usman or ones listed in the articles should work. Instead, I just made a snapshot of my entire server, which I DID end up needing once because something broke.

3. Config mariadb for proper shutdown

  • run cat /etc/cyberpanel/mysqlPassword to get your mariadb root password
  • run mysql -u root -p
  • enter password

Run these commands within mariadb cli

SET GLOBAL innodb_fast_shutdown = 1;
XA RECOVER;
exit;

4. Remove MariaDB

  • run systemctl stop mariadb
  • confirm it is stopped with systemctl status mariadb. The output is convoluted, but look for following lines
Active: inactive (dead) since Wed 2022-03-16 14:13:25 CST; 1s ago
Status: "MariaDB server is down"
  • run apt list --installed | grep -i -E "mariadb|galera" to confirm which packages will be removed
  • run apt remove "*mariadb*" "galera*" -y
  • run apt list --installed | grep -i -E "mariadb|galera" again to confirm all those packages were removed

5. Install New Version of MariaDB

  • run the following command, changing 10.6 for whichever version you would like to install. 10.11 is the latest LTS version.
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.6"
  • run apt update
  • run apt install mariadb-server libmariadb-dev -y
  • when prompted with this, enter N
Configuration file '/etc/mysql/mariadb.conf.d/50-server.cnf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** 50-server.cnf (Y/I/N/O/D/Z) [default=N] ?
  • run apt update && apt upgrade -y to update all packages again (there’s a mysql-common package that got updated from 5.8 to 10.6.7 for me)

  • run apt list --installed | grep -i -E "mariadb|galera" to confirm which packages were installed
    Note: don’t worry that libmariadbclient-dev is not installed as it was before. It appears to have been deprecated/replaced by libmariadb-dev, which was installed.

  • run systemctl enable mariadb

  • run systemctl start mariadb

  • run systemctl status mariadb to confirm version and active

  • run mysql_upgrade -u root -p.

This is CRITICAL, and not mentioned in the method above. Here are detailed investigations into what mysql_upgrade does

  • enter password from previously

Note: it might be worth upgrading CyberPanel after all of this. It is harmless, might pre-emptively fix any issues, and might even give you some minor updates that have not yet been included in an official release. Run

sh <(curl https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh || wget -O - https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/preUpgrade.sh) 

as per the instructions here Upgrading CyberPanel - Docs

2 Likes

Great info @nick.chomey . But you missed to mention about the file /etc/mysql/mariadb.conf.d/50-server.cnf' which it will ask whether to keep the old file or the replace it with new.

1 Like

Ah, yes. Thanks. I kept the old file (default setting) - is that correct?

What we really need to do is update Usman’s original Documentation post in this topic, as its a very important topic. But it should also include instructions for RHEL, which I don’t know anything about.

The topic is a Wiki Post, which means you/anyone can edit it. Do you think you could take what I’ve written, add what is necessary for RHEL, and make any other relevant changes?

Also, please see the comment I just made here about MariaDB errors that are ONLY occurring when CyberPanel is installed on Ubuntu (no issue when using Ubuntu without CP). MariaDB errors on Ubuntu 20.04 ONLY when using CyberPanel - Support and Discussion / General Discussion - CyberPanel Community

1 Like

Try this way on almalinux 8, but it will also remove pure-ftpd ?

No idea. Try it on a dummy server!

Working and tested!!!

Requirements:

  1. A server running Ubuntu 20.04 LTS.
  2. A version of MariaDB running that is not the latest.
  3. Root access to the server.
  4. Cyber Panel in lastest version

Upgrade MariaDB in Ubuntu 20.04 LTS

First update and upgrade your system:

$ sudo apt upgrade && sudo apt upgrade -y

A MariaDB upgrade in Ubuntu requires uninstalling the old version and installing the new version. The best practice is to take a backup before changing the existing server if issues arise.

These issues may corrupt the database files, preventing you from quickly reverting to the older version. A backup allows restoration if needed and can be deleted once the upgrade is successful.

Step 1: Backup MariaDB (use your way…)

Step 2: Stop MariaDB

Stop MariaDB from running using the following command.

$ sudo systemctl stop mariadb

Step 3: Uninstall the Old Version of MariaDB

The upgrade process requires uninstalling the old version before installing the new version of MariaDB. Use the following command to uninstall the previous version.

$ sudo apt-get remove mariadb-server

Step 4: Install the Latest Version of MariaDB on Ubuntu

Install the latest version of MariaDB via the APT package manager (Debian/Ubuntu).

  1. Configure the APT package repository. This step involves adding a key for the MariaDB server repo and then updating.

$ sudo apt install wget

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

$ echo "fd3f41eefff54ce144c932100f9e0f9b1d181e0edd86a6f6b8f2a0212100c32c mariadb_repo_setup"

$ chmod +x mariadb_repo_setup

$ sudo ./mariadb_repo_setup \ --mariadb-server-version="mariadb-10.11"

$ sudo apt update

  1. Install MariaDB and package dependencies. Installing additional packages may require additional plugins.

$ sudo apt install mariadb-server

  1. Once you start the server processes, run the below utility to upgrade the data directory. MariaDB comes with the mariadb-upgrade utility, which identifies and corrects the compatibility issues in the latest version.

$ sudo mariadb-upgrade

  1. You can now enable and start MariaDB with the following command.

$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb

that’s it… it worked very well in this environment

Ubuntu 20.04
Cyber Panel latest version

3 Likes

Can someone help me.
The first option:
cat /etc/yum.repos.d/mariadb.repo

i get error: No such file or directory

Just create a new one, follow this

Thanks for this, but this downloads repository no longer exists. Thanks!

this still works, just tested link

1 Like

Will the update takedown a website?

You are correct. For some reason it was failing when I tried. Must have been on my end.

If the website has a dependency on mariadb like WP then it will be disrupted until you can successfully upgrade. I bricked my sandbox test WP sites before I got it working smoothly using these instructions. Just perform a backup a full backup before you attempt to upgrade.

1 Like

How long does the upgrade take?

I have to find a time slot with the least traffic to perform this task.

I was up and running between 7 - 10 minutes. However, duration will ultimately depend on your environment & use case (#/size WP sites, other dependent apps, etc.)

1 Like

Great. I think this is okay. Cloudflare will serve the cached page during the upgrade and only a few visitors will be affected. Thanks for the info.

It still looks like Cyberpanel still comes with an older version of MariaDB v10.3.

I have double-checked this on multiple Cyberpanel installation on Ubuntu 20 and 22 and after afresh install, MariaDB shows version 10.3.

UPDATE (December 1, 2023)
Looks like @usmannasir silently fixed this flaw. Cyberpanel now installs with MariaDB 10.6.

I have a zero-downtime approach to upgrading MariaDB.

  1. Connect your website to Cloudflare.

  2. Enable API access on your current CyberPanel installation. Let’s call it the MAIN SERVER.

  3. Get a TEMPORARY SERVER, preferably from Hetzner (They bill based on hours. You’ll need around 3 hours or you can take your time)

  4. Install CyberPanel on your temporary server.

  5. Access CyberPanel on your temporary server and go Menu > Main > Backup > Remote Backup.

  6. Enter the IP Address and Admin password of your main server. This only works if your main server access to the CyberPanel port is set to 8090. If you’ve changed it to something else, switch it back to 8090.

  1. Click the Fetch Accounts button that shows after entering the details in Step 6.

  2. Select the sites that show up and choose start transfer.

It may take some time, depending on the size of your website (s).

This action moves your whole site including databases, SSL certificates, mail accounts, and pretty much everything associated with the sites on your main server.

  1. The Remote Backup file for your site will be saved on your temporary server’s root folder accessible under Home > Backup > Transfer-1234 > backup-yoursite.com-date.tar.

  2. Transfer the .tar file to the Home > Backup folder. I used SFTP access. Somehow, moving/copying the file using CyberPanel’s Root File Manager didn’t work.

  3. Go back to Step 5 in CyberPanel on your temporary server, but this time select Restore Backup.

  4. Choose Select Backup and pick the .tar backup file for your website. This may take some time and CyberPanel will show you the steps being undertaken from start to finish.

  5. Once backup has been restored, confirm that your website is working internally by going to CyberPanel on your temporary server and access Menu > Main > List Websites. Choose Manage next to your website under that submenu. Then click Preview next to the domain name under Manage.

  6. Once confirmed, go to Cloudflare and change the IP address on the A Record of your domain to that of your temporary server. This switch is instant and Cloudflare will start pointing users to your website on the temporary server.

  7. Now go back to your main server and do a fresh install of the operating system.

  8. Once done, open SSH on your main server and install a current copy of MariaDB. First, check for MariaDB version using the script mariadb --version.

Ubuntu will inform you that MariaDB isn’t installed and it will suggest the script you need to run to install the latest MariaDB. Run it to install MariaDB, then use the script under Step 16 to confirm the installed version.

  1. Now repeat Steps 4 - 14 but this time you will be reverting your website from the temporary server back to your main server. And don’t forget to double-check the DNS Records on both Cloudflare and CyberPanel.

  2. Destroy the temporary server.

UPDATE: December 3, 2023

It looks like @usmannasir has silently made some changes.

From Step 8 - 12: The backup is now being automatically installed on the new server (temporary server) on OpenLiteSpeed.

Unfortunately, Usman has broken the feature for LiteSpeed Enterprise users. It’s not importing backups from the remote server nor installing them, despite showing a log of events claiming everything has been done successfully.