How to upgrade MySQL & MariaDB on Linux Cloud Servers

2020-06-29 By Sam 19439 Views linux mysql mariadb development
3 reviews

MySQL & MariaDB are open-source relational database management systems and are possible to use in most Linux distributions. It uses SQL (Structured Query Language) to manage its data.


This guide outlines the basic steps required to upgrade MySQL and MariaDB on Linux systems.


To upgrade MySQL 5.6 to 5.7 on CentOS 7

  1. Check the current version of MySQL on the server.

    # mysql --version
    

    upgradedb1

  2. Before initiating the upgrade, take the full backup of all databases that exist on the server with the below command.

    # mysqldump -u root -p --all-databases > /tmp/all-database.sql
    


    Enter the root password and then the all-database.sql will be created under /tmp directory:

    upgradedb2

  3. Stop MySQL service with the below command.

    # systemctl stop mysqld
    

    upgradedb3

  4. Now create the backup of the current MySQL data with the below command.

    # cp -r /var/lib/mysql /var/lib/mysql.backup
    

    upgradedb4

  5. Download the MySQL RPM which needs to upgrade. Here downloading the MySQL 5.7 RPM to /tmp directory with the below command.

    # wget http://repo.mysql.com/mysql57-community-release-el7.rpm -P /tmp/
    
  6. List the /tmp directory on the server to verify whether it downloaded.

    # cd /tmp/
    
    # ll | grep mysql
    

    upgradedb5

  7. Now need to remove the MySQL-Community RPM that contains the current version of MySQL 5.6.

    # yum remove mysql-community-release
    

    upgradedb6

  8. Install the recently downloaded MySQL 5.7 RPM/

    # rpm -ivh /tmp/mysql57-community-release-el7.rpm
    

    upgradedb7

  9. Update the MySQL repository to the recently installed 5.7.

    # yum update mysql
    

    upgradedb8

  10. Now restart the MySQL service and check the version with the below commands.

    # systemctl restart mysqld
    
    # mysql --version
    

    upgradedb9

  11. Here from the last image, you can verify that the MySQL service upgraded from 5.6 to 5.7.


To upgrade MySQL 5.7 to 8.0 on Ubuntu/Debian

  1. Check the current version of the MySQL on the server

    # mysql --version
    

    upgradedb10

  2. Before initiating the upgrade, take the full backup of all databases that exist on the server with the below command.

    # mysqldump -u root -p --all-databases > /tmp/all-database.sql
    


    Enter the root password and then the all-database.sql will be created under /tmp directory:

    upgradedb11

  3. Stop MySQL service with the below command.

    # systemctl stop mysql.service
    

    upgradedb12

  4. Now create the backup of the current MySQL data with the below command.

    # cp -r /var/lib/mysql /var/lib/mysql.backup
    

    upgradedb13

  5. Now download the MySQL APT repository.

    # wget https://repo.mysql.com//mysql-apt-config_0.8.14-1_all.deb
    

    upgradedb14

  6. Then add the MySQL APT repository to the server’s software repository list with the below command.

    # dpkg -i mysql-apt-config_0.8.14-1_all.deb
    


    The below screens will get and select the MySQL Server & Cluster option and press enter.

    upgradedb15


    Now select the mysql-8.0 and press OK.

    upgradedb16


    Click on the below-mentioned OK to finish.

    upgradedb17


    Then will get the below message.

    upgradedb18

  7. Now update the server and install the latest MySQL using the below commands.

    # apt-get update
    
    # apt-get install mysql-server
    

    upgradedb19

    upgradedb20

  8. Now restart the MySQL service and check the version with the below commands.

    # systemctl restart mysql.service
    
    # mysql --version
    

    upgradedb21

  9. Here from the last image, you can verify that the MySQL service upgraded from 5.7 to 8.0.


To upgrade MariaDB 5.5 to 10.1 on CentOS 7

  1. Check the current version of the MariaDB on the server and Enter the MariaDB root password.

    # mysqladmin -u root -p version
    

    upgradedb22

  2. Before initiating the upgrade, take the full backup of all databases that exist on the server with the below command.

    # mysqldump -u root -p --all-databases > /tmp/all-database.sql
    


    Enter the MariaDB root password and then the all-database.sql will be created under /tmp directory.

    upgradedb23

  3. Stop MariaDB service with the below command.

    # systemctl stop mariadb
    

    upgradedb24

  4. Now create the backup of the current MariaDB data with the below command.

    # cp -r /var/lib/mysql /var/lib/mysql.backup
    

    upgradedb25

  5. Now need to add the latest MariaDB 10.1 repo for CentOS 7 distributions. For that add the following text in /etc/yum.repos.d/MariaDB10.repo with the text editor vi.

    # MariaDB 10.1 CentOS repository list - created 2016-01-18 09:58 UTC
    
    # http://mariadb.org/mariadb/repositories/
    
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.1/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    

    upgradedb26

  6. Now remove the current MariaDB 5.5 from the server with the below command.

    # yum remove mariadb-server mariadb mariadb-libs
    

    upgradedb27

  7. Then remove the repository cache with the below command.

    # yum clean all
    

    upgradedb28

  8. Now proceed with the Installation MariaDB 10.1.

    # yum install MariaDB-server MariaDB-client
    

    upgradedb29

  9. Once the installation is completed, start and enable MariaDB.

    # systemctl start mariadb
    
    # systemctl enable mariadb
    

    upgradedb30

  10. Now run the below command to check the new version of MariaDB.

    # mysqladmin -u root -p version
    


    Enter the MariaDB root password.

    upgradedb31

  11. Here from the last image, you can verify that the MariaDB server upgraded from 5.5 to 10.1.


To upgrade MariaDB 10.1 to 10.5 on Ubuntu/Debian

  1. Run the below command to check the current version of the MariaDB on the server and Enter the MariaDB root password.

    # mysqladmin -u root -p version
    

    upgradedb32

  2. Before initiating the upgrade, take the full backup of all databases that exist on the server with the below command.

    # mysqldump -u root -p --all-databases > /tmp/all-database.sql
    


    Enter the MariaDB root password and then the all-database.sql will be created under /tmp directory:

    upgradedb33

  3. Stop MariaDB service with the below command.

    # systemctl stop mariadb
    

    upgradedb34

  4. Now create the backup of the current MariaDB data with the below command.

    # cp -r /var/lib/mysql /var/lib/mysql.backup
    

    upgradedb35

  5. Now run the below commands to add the MariaDB PPA on the server.

    # apt-get install software-properties-common
    

    upgradedb36

    # apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
    

    upgradedb37

    # add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.supportex.net/mariadb/repo/10.5/ubuntu bionic main'
    

    upgradedb38

    NOTE: Replace ubuntu bionic with your distribution name and release.

  6. Now remove the current MariaDB 10.1 from the server with the below command.

    # apt remove mariadb-server
    

    upgradedb39

  7. Then remove the repository cache with the below command.

    # apt-get clean all
    

    upgradedb40

  8. Now proceed with the Installation MariaDB 10.5

    # apt-get install mariadb-server
    

    upgradedb41

  9. Once the installation is completed, start and enable MariaDB.

    # systemctl start mariadb
    
    # systemctl enable mariadb
    

    upgradedb42

  10. Now run the below command to check the new version of MariaDB.

    # mysqladmin -u root -p version
    


    Enter the MariaDB root password.

    upgradedb43

  11. Here from the last image, you can verify that the MariaDB server upgraded from 10.1 to 10.5.


Related Tutorials

What do you think about this article?

Rate this article
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.