• How to upgrade MySQL 5.5 to 5.6/5.7 or MariaDB 5.5 to 10.x on CentOS 7

By default, CentOS 7 is shipped with MariaDB 5.5. MariaDB 10.x version is a drop-in replacement for MySQL 5.5-5.7.

Automatic method if you are running Plesk

Note: The script will upgrade the default MariaDB 5.5 to the latest MariaDB version 10.5. Make sure Obsidian 18.0.30 or later is installed on the server.

Download the attached script and provide it with executable rights:

wget https://plesk.zendesk.com/hc/article_attachments/360022419980/mariadb-10.5-upgrade.sh && chmod +x mariadb-10.5-upgrade.sh

Execute the script via CLI:

./mariadb-10.5-upgrade.sh

Manual Method

For security reasons, create a database dump of all databases with the following command:

MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -u admin --verbose --all-databases --routines --triggers > /tmp/all-databases.sql

Stop MariaDB:

service mariadb stop

Remove additional mariadb-bench package if installed:

rpm -e --nodeps mariadb-bench

For security reasons, copy the database directory in a separate folder:

cp -v -a /var/lib/mysql/ /var/lib/mysql_backup

Check if the mysql-server package is already installed:

rpm -q --whatprovides mysql-server

If it is installed and the command above gives output, remove using the following command:

rpm -e --nodeps `rpm -q --whatprovides mysql-server`

Configure MariaDB repository: open the Setting MariaDB repositories page, select your OS distro, release, and desired MariaDB version. Once done, the configuration that should be added to the /etc/yum.repos.d/MariaDB.repo file will appear.

Warning: MariaDB 10.4 and 10.5 are supported since 18.0.30, make sure the latest Plesk version is installed.

Here is an example for MariaDB 10.5:

Open/create the MariaDB.repo file in any text editor. In this example, we are using the vi editor:

vi /etc/yum.repos.d/MariaDB.repo

Add the content below to the file:

mariadb]  
name = MariaDB  
baseurl = http://yum.mariadb.org/10.5/centos7-amd64   
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB   
gpgcheck=1

Save the changes and close the file.

Start an upgrade of MariaDB:

yum install MariaDB-client MariaDB-server MariaDB-compat MariaDB-shared

Once the upgrade is finished, start MariaDB:

systemctl restart mariadb

OR

systemctl restart mysql

Upgrade MySQL databases:

MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin

Restart mysql service:

systemctl restart mariadb

OR

systemctl restart mysql

Execute this command to update the package version inside Plesk:

plesk sbin packagemng -sdf

Note: After an upgrade, there may appear 'mysql' init script. It should be removed to avoid conflicts with MariaDB service. The same commands can be used to fix already existing conflict:

systemctl stop mysql; killall mysqld # to stop the incorrect service if it is started
rm /etc/init.d/mysql && systemctl daemon-reload # to remove the incorrect service script and reload systemctl configuration
systemctl start mariadb # to start MariaDB if not started
systemctl enable mariadb # to make sure that MariaDB will start after the server reboot automatically

This article was last modified: March 3, 2021, 3:37 p.m.

0 Comments

Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.

Share

Hacker News

Top