I was working on CentOS/RHEL 7. In this latest version of OS we have 5.5.52-MariaDB. In case we need update MySQL to latest 5.7 version we should follow MySQL repositories. In this post we would see Upgrading MySQL with MySQL Yum Repository in CentOS/RHEL 7.

We are targeting to MySQL/MariaDB 5.5 version installed in CentOS/RHEL 7 by default, updade it to MySQL 5.7. It Always suggested to updade to MySQL 5.6 first before upgrading to 5.7.

Setup

So we have below setup on which we used to work for this post

[root@srv7-master ~]# mysqltest --version
mysqltest  Ver 3.4 Distrib 5.5.52-MariaDB, for Linux (x86_64)

[root@srv7-master ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

[root@srv7-master ~]# uname  -r
3.10.0-514.26.2.el7.x86_64

Prerequisite

So to updade, first we should stop MySQL Server running on Machine.

[root@srv7-master ~]# systemctl stop mariadb

[root@srv7-master ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2017-08-15 07:22:07 IST; 12s ago
  Process: 1005 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 1004 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
  Process: 923 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 1004 (code=exited, status=0/SUCCESS)

Aug 15 06:33:50 srv7-master systemd[1]: Starting MariaDB database server...
Aug 15 06:33:50 srv7-master mysqld_safe[1004]: 170815 06:33:50 mysqld_safe L....
Aug 15 06:33:50 srv7-master mysqld_safe[1004]: 170815 06:33:50 mysqld_safe S...l
Aug 15 06:33:52 srv7-master systemd[1]: Started MariaDB database server.
Aug 15 07:22:06 srv7-master systemd[1]: Stopping MariaDB database server...
Aug 15 07:22:07 srv7-master systemd[1]: Stopped MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.

Now we need to add MySQL official repository for up-gradation.Download MySQL community release RPM for repository files, like epel or centos release files.

# wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm 

Saving to: ‘mysql57-community-release-el7-11.noarch.rpm’

100%[======================================>] 25,680      --.-K/s   in 0.02s   

2017-08-15 07:24:12 (1.33 MB/s) - ‘mysql57-community-release-el7-11.noarch.rpm’ saved [25680/25680]


[root@srv7-master ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-11 ################################# [100%]

Now check available repositories on system.

[root@srv7-master ~]# yum repolist all| grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     39
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community/x86_64       MySQL Tools Community         enabled:     49
mysql-tools-community-source       MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
mysql55-community-source           MySQL 5.5 Community Server -  disabled
mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
mysql56-community-source           MySQL 5.6 Community Server -  disabled
mysql57-community/x86_64           MySQL 5.7 Community Server    enabled:    207
mysql57-community-source           MySQL 5.7 Community Server -  disabled
mysql80-community/x86_64           MySQL 8.0 Community Server    disabled
mysql80-community-source           MySQL 8.0 Community Server -  disabled

Now we can see most community-server repository are disable except 5.7, we need to disable it and enable 5.6 first.

yum-config-manager --disable mysql57-community
yum-config-manager --enable  mysql56-community

This yum-config-manager commands comes with yum-utils package.

[root@srv7-master ~]# rpm -qf /bin/yum-config-manager
yum-utils-1.1.31-40.el7.noarch

Now we could update MySQL server.

[root@srv7-master ~]# yum update mysql-community-server


Dependencies Resolved

================================================================================
 Package                   Arch      Version         Repository            Size
================================================================================
Installing:
 mysql-community-client    x86_64    5.6.37-2.el7    mysql56-community     19 M
     replacing  mariadb.x86_64 1:5.5.52-1.el7
 mysql-community-devel     x86_64    5.6.37-2.el7    mysql56-community    3.4 M
     replacing  mariadb-devel.x86_64 1:5.5.52-1.el7
 mysql-community-libs      x86_64    5.6.37-2.el7    mysql56-community    2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-server    x86_64    5.6.37-2.el7    mysql56-community     59 M
     replacing  mariadb-server.x86_64 1:5.5.52-1.el7
Installing for dependencies:
 mysql-community-common    x86_64    5.6.37-2.el7    mysql56-community    257 k

Transaction Summary
================================================================================
Install  4 Packages (+1 Dependent package)

Total download size: 84 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.37-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.6.37-2.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.6.37-2.el7.x86_64.rpm      | 257 kB   00:01     
(2/5): mysql-community-devel-5.6.37-2.el7.x86_64.rpm       | 3.4 MB   00:09     
(3/5): mysql-community-libs-5.6.37-2.el7.x86_64.rpm        | 2.0 MB   00:12     
(4/5): mysql-community-client-5.6.37-2.el7.x86_64.rpm      |  19 MB   01:04     
(5/5): mysql-community-server-5.6.37-2.el7.x86_64.rpm      |  59 MB   01:58     
--------------------------------------------------------------------------------
Total                                              609 kB/s |  84 MB  02:21     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-11.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.6.37-2.el7.x86_64                   1/9 
  Installing : mysql-community-libs-5.6.37-2.el7.x86_64                     2/9 
  Installing : mysql-community-client-5.6.37-2.el7.x86_64                   3/9 
  Installing : mysql-community-server-5.6.37-2.el7.x86_64                   4/9 
  Installing : mysql-community-devel-5.6.37-2.el7.x86_64                    5/9 
  Erasing    : 1:mariadb-server-5.5.52-1.el7.x86_64                         6/9 
warning: /var/log/mariadb/mariadb.log saved as /var/log/mariadb/mariadb.log.rpmsave
  Erasing    : 1:mariadb-devel-5.5.52-1.el7.x86_64                          7/9 
  Erasing    : 1:mariadb-5.5.52-1.el7.x86_64                                8/9 
  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                           9/9 
  Verifying  : mysql-community-libs-5.6.37-2.el7.x86_64                     1/9 
  Verifying  : mysql-community-common-5.6.37-2.el7.x86_64                   2/9 
  Verifying  : mysql-community-server-5.6.37-2.el7.x86_64                   3/9 
  Verifying  : mysql-community-devel-5.6.37-2.el7.x86_64                    4/9 
  Verifying  : mysql-community-client-5.6.37-2.el7.x86_64                   5/9 
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                6/9 
  Verifying  : 1:mariadb-server-5.5.52-1.el7.x86_64                         7/9 
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                           8/9 
  Verifying  : 1:mariadb-devel-5.5.52-1.el7.x86_64                          9/9 

Installed:
  mysql-community-client.x86_64 0:5.6.37-2.el7                                  
  mysql-community-devel.x86_64 0:5.6.37-2.el7                                   
  mysql-community-libs.x86_64 0:5.6.37-2.el7                                    
  mysql-community-server.x86_64 0:5.6.37-2.el7                                  

Dependency Installed:
  mysql-community-common.x86_64 0:5.6.37-2.el7                                  

Replaced:
  mariadb.x86_64 1:5.5.52-1.el7         mariadb-devel.x86_64 1:5.5.52-1.el7    
  mariadb-libs.x86_64 1:5.5.52-1.el7    mariadb-server.x86_64 1:5.5.52-1.el7   

Complete!

Now start MySQL.

[root@srv7-master ~]# systemctl start mysqld

Let’s do some checks for database.

[root@srv7-master ~]# mysqlshow 
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+

[root@srv7-master ~]# mysqltest --version
mysqltest  Ver 3.3 Distrib 5.6.37, for Linux (x86_64)

As we can see, My database are same as earlier and MySQL version update to verion 5.6. Now I need to update it to 5.7.

For updating it, again stop MYSQL service

[root@srv7-master ~]# systemctl stop mysqld

[root@srv7-master ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Wed 2017-08-16 06:27:52 IST; 7s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 961 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 925 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1016 (code=exited, status=0/SUCCESS)

Aug 16 06:10:11 srv7-master systemd[1]: Starting MySQL Server...
Aug 16 06:10:14 srv7-master systemd[1]: Started MySQL Server.
Aug 16 06:27:50 srv7-master systemd[1]: Stopping MySQL Server...
Aug 16 06:27:52 srv7-master systemd[1]: Stopped MySQL Server.

Enable 5.7 community server repository.

yum-config-manager --enable  mysql57-community

now just update it once more.

[root@srv7-master ~]# yum update 
Loaded plugins: fastestmirror
mysql-connectors-community                               | 2.5 kB     00:00     
mysql-tools-community                                    | 2.5 kB     00:00     
mysql56-community                                        | 2.5 kB     00:00     
mysql57-community                                        | 2.5 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: centos.mirror.snu.edu.in
 * epel: mirror.vinahost.vn
 * extras: centos.mirror.snu.edu.in
 * updates: mirror.ehost.vn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.37-2.el7 will be updated
---> Package mysql-community-client.x86_64 0:5.7.19-1.el7 will be an update
---> Package mysql-community-common.x86_64 0:5.6.37-2.el7 will be updated
---> Package mysql-community-common.x86_64 0:5.7.19-1.el7 will be an update
---> Package mysql-community-devel.x86_64 0:5.6.37-2.el7 will be updated
---> Package mysql-community-devel.x86_64 0:5.7.19-1.el7 will be an update
---> Package mysql-community-libs.x86_64 0:5.6.37-2.el7 will be updated
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: php-mysql-5.4.16-42.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: php-mysql-5.4.16-42.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.19-1.el7 will be an update
---> Package mysql-community-server.x86_64 0:5.6.37-2.el7 will be updated
---> Package mysql-community-server.x86_64 0:5.7.19-1.el7 will be an update
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.19-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                      Arch    Version          Repository          Size
================================================================================
Updating:
 mysql-community-client       x86_64  5.7.19-1.el7     mysql57-community   24 M
 mysql-community-common       x86_64  5.7.19-1.el7     mysql57-community  272 k
 mysql-community-devel        x86_64  5.7.19-1.el7     mysql57-community  3.6 M
 mysql-community-libs         x86_64  5.7.19-1.el7     mysql57-community  2.1 M
 mysql-community-server       x86_64  5.7.19-1.el7     mysql57-community  164 M
Installing for dependencies:
 mysql-community-libs-compat  x86_64  5.7.19-1.el7     mysql57-community  2.0 M

Transaction Summary
================================================================================
Install             ( 1 Dependent package)
Upgrade  5 Packages

Total download size: 196 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/6): mysql-community-common-5.7.19-1.el7.x86_64.rpm      | 272 kB   00:01     
(2/6): mysql-community-devel-5.7.19-1.el7.x86_64.rpm       | 3.6 MB   00:24     
(3/6): mysql-community-libs-5.7.19-1.el7.x86_64.rpm        | 2.1 MB   00:05     
(4/6): mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm | 2.0 MB   00:05     
(5/6): mysql-community-client-5.7.19-1.el7.x86_64.rpm      |  24 MB   00:58     
(6/6): mysql-community-server-5.7.19-1.el7.x86_64.rpm      | 164 MB   05:50     
--------------------------------------------------------------------------------
Total                                              519 kB/s | 196 MB  06:26     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : mysql-community-common-5.7.19-1.el7.x86_64                  1/11 
  Updating   : mysql-community-libs-5.7.19-1.el7.x86_64                    2/11 
  Updating   : mysql-community-client-5.7.19-1.el7.x86_64                  3/11 
  Updating   : mysql-community-server-5.7.19-1.el7.x86_64                  4/11 
  Updating   : mysql-community-devel-5.7.19-1.el7.x86_64                   5/11 
  Installing : mysql-community-libs-compat-5.7.19-1.el7.x86_64             6/11 
  Cleanup    : mysql-community-devel-5.6.37-2.el7.x86_64                   7/11 
  Cleanup    : mysql-community-server-5.6.37-2.el7.x86_64                  8/11 
  Cleanup    : mysql-community-client-5.6.37-2.el7.x86_64                  9/11 
  Cleanup    : mysql-community-libs-5.6.37-2.el7.x86_64                   10/11 
  Cleanup    : mysql-community-common-5.6.37-2.el7.x86_64                 11/11 
  Verifying  : mysql-community-libs-5.7.19-1.el7.x86_64                    1/11 
  Verifying  : mysql-community-client-5.7.19-1.el7.x86_64                  2/11 
  Verifying  : mysql-community-devel-5.7.19-1.el7.x86_64                   3/11 
  Verifying  : mysql-community-libs-compat-5.7.19-1.el7.x86_64             4/11 
  Verifying  : mysql-community-common-5.7.19-1.el7.x86_64                  5/11 
  Verifying  : mysql-community-server-5.7.19-1.el7.x86_64                  6/11 
  Verifying  : mysql-community-server-5.6.37-2.el7.x86_64                  7/11 
  Verifying  : mysql-community-libs-5.6.37-2.el7.x86_64                    8/11 
  Verifying  : mysql-community-common-5.6.37-2.el7.x86_64                  9/11 
  Verifying  : mysql-community-devel-5.6.37-2.el7.x86_64                  10/11 
  Verifying  : mysql-community-client-5.6.37-2.el7.x86_64                 11/11 

Dependency Installed:
  mysql-community-libs-compat.x86_64 0:5.7.19-1.el7                             

Updated:
  mysql-community-client.x86_64 0:5.7.19-1.el7                                  
  mysql-community-common.x86_64 0:5.7.19-1.el7                                  
  mysql-community-devel.x86_64 0:5.7.19-1.el7                                   
  mysql-community-libs.x86_64 0:5.7.19-1.el7                                    
  mysql-community-server.x86_64 0:5.7.19-1.el7                                  

Complete!

Now let’s do some checks again.

[root@srv7-master ~]# mysqlcheck --version
mysqlcheck  Ver 2.5.1 Distrib 5.7.19, for Linux (x86_64)

[root@srv7-master ~]# mysqlshow 
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+