【オレ流】Upgrading from MariaDB 10.1 to MariaDB 10.2

MariaDBのバージョンを10.1から10.2にアップグレードしました。バージョンナンバーで言えば「たったコンマ1」のアップグレードなので、WordPressのようにボタンひとつで簡単に行えるかと思いがちですが、実際はそうではありません。

公式サイトのUpgrading from MariaDB 10.1 to MariaDB 10.2MariaDB 10.1 を 10.2 にアップデートする方法 | LuftGardenのやり方でアップグレードしようとすると、rpmパッケージの依存関係で色々と面倒なので、一部のみ参考とさせていただきました。

[root@server ~]# mysqldump -u root -p --all-databases > /root/mariadb_backup_all.sql
Enter password:
[root@server ~]# systemctl stop mariadb

まずはデータベース全体のバックアップを取得して、MariaDBのサービスを停止します。もし停止し忘れてもアンイストールの時点で勝手に止まりますので心配いりません。

[root@server ~]# yum remove -y MariaDB-server
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-server.x86_64 0:10.1.34-1.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                       Arch                  Version                              Repository               Size
========================================================================================================================
Removing:
 MariaDB-server                x86_64                10.1.34-1.el7.centos                 @mariadb                450 M

Transaction Summary
========================================================================================================================
Remove  1 Package

Installed size: 450 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : MariaDB-server-10.1.34-1.el7.centos.x86_64                                                           1/1
warning: /etc/my.cnf.d/server.cnf saved as /etc/my.cnf.d/server.cnf.rpmsave
  Verifying  : MariaDB-server-10.1.34-1.el7.centos.x86_64                                                           1/1

Removed:
  MariaDB-server.x86_64 0:10.1.34-1.el7.centos

Complete!
[root@server ~]#

MariaDB-serverのみをアンインストールします。MariaDB-serverのみ”yum update”コマンドでアップデートしようとすると、手動で削除しろと怒られます。

[root@server ~]# cat > /etc/yum.repos.d/MariaDB.repo <<'EOF'
# MariaDB 10.2 CentOS repository list - created 2018-07-12 08:09 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
[root@server ~]#

リポジトリをMariaDB 10.2のものに書き換えます。”sed -i -e ‘s|10.1|10.2|g’ /etc/yum.repos.d/MariaDB.repo”コマンドを実行して、10.1のところを10.2に書き換えるだけでもOKです。

[root@server ~]# yum -y install MariaDB-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
mariadb                                                                                          | 2.9 kB  00:00:00
mariadb/primary_db                                                                               |  61 kB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-server.x86_64 0:10.2.16-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                       Arch                  Version                               Repository              Size
========================================================================================================================
Installing:
 MariaDB-server                x86_64                10.2.16-1.el7.centos                  mariadb                110 M

Transaction Summary
========================================================================================================================
Install  1 Package

Total download size: 110 M
Installed size: 466 M
Downloading packages:
MariaDB-10.2.16-centos73-x86_64-server.rpm                                                       | 110 MB  00:01:22
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : MariaDB-server-10.2.16-1.el7.centos.x86_64                                                           1/1
  Verifying  : MariaDB-server-10.2.16-1.el7.centos.x86_64                                                           1/1

Installed:
  MariaDB-server.x86_64 0:10.2.16-1.el7.centos

Complete!
[root@server ~]#

MariaDB-server-10.2をインストールします。

[root@server ~]# mkdir -p /etc/my.cnf.d/backup
[root@server ~]# \mv /etc/my.cnf.d/{server.cnf,backup/server.cnf-orig}
[root@server ~]# \mv /etc/my.cnf.d/server.cnf{.rpmsave,}
[root@server ~]# sed -i -e '/-10\.1/s|\.1|\.2|g' /etc/my.cnf.d/server.cnf

MariaDB-serverの設定ファイルをリストアします。インストールで作成された/etc/my.cnf.d/server.cnfは上書きする前にバックアップをとっておきます。

[root@server ~]# yum -y update MariaDB-*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.1.34-1.el7.centos will be updated
---> Package MariaDB-client.x86_64 0:10.2.16-1.el7.centos will be an update
---> Package MariaDB-common.x86_64 0:10.1.34-1.el7.centos will be updated
---> Package MariaDB-common.x86_64 0:10.2.16-1.el7.centos will be an update
---> Package MariaDB-compat.x86_64 0:10.1.34-1.el7.centos will be updated
---> Package MariaDB-compat.x86_64 0:10.2.16-1.el7.centos will be an update
---> Package MariaDB-devel.x86_64 0:10.1.34-1.el7.centos will be updated
---> Package MariaDB-devel.x86_64 0:10.2.16-1.el7.centos will be an update
---> Package MariaDB-shared.x86_64 0:10.1.34-1.el7.centos will be updated
---> Package MariaDB-shared.x86_64 0:10.2.16-1.el7.centos will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                       Arch                  Version                               Repository              Size
========================================================================================================================
Updating:
 MariaDB-client                x86_64                10.2.16-1.el7.centos                  mariadb                 48 M
 MariaDB-common                x86_64                10.2.16-1.el7.centos                  mariadb                157 k
 MariaDB-compat                x86_64                10.2.16-1.el7.centos                  mariadb                2.8 M
 MariaDB-devel                 x86_64                10.2.16-1.el7.centos                  mariadb                6.6 M
 MariaDB-shared                x86_64                10.2.16-1.el7.centos                  mariadb                393 k

Transaction Summary
========================================================================================================================
Upgrade  5 Packages

Total download size: 58 M
Downloading packages:
No Presto metadata available for mariadb
(1/5): MariaDB-10.2.16-centos73-x86_64-common.rpm                                                | 157 kB  00:00:01
(2/5): MariaDB-10.2.16-centos73-x86_64-compat.rpm                                                | 2.8 MB  00:00:02
(3/5): MariaDB-10.2.16-centos73-x86_64-devel.rpm                                                 | 6.6 MB  00:00:07
(4/5): MariaDB-10.2.16-centos73-x86_64-shared.rpm                                                | 393 kB  00:00:00
(5/5): MariaDB-10.2.16-centos73-x86_64-client.rpm                                                |  48 MB  00:00:26
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   2.2 MB/s |  58 MB  00:00:26
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : MariaDB-compat-10.2.16-1.el7.centos.x86_64                                                          1/10
  Updating   : MariaDB-common-10.2.16-1.el7.centos.x86_64                                                          2/10
  Updating   : MariaDB-devel-10.2.16-1.el7.centos.x86_64                                                           3/10
  Updating   : MariaDB-shared-10.2.16-1.el7.centos.x86_64                                                          4/10
  Updating   : MariaDB-client-10.2.16-1.el7.centos.x86_64                                                          5/10
  Cleanup    : MariaDB-devel-10.1.34-1.el7.centos.x86_64                                                           6/10
  Cleanup    : MariaDB-client-10.1.34-1.el7.centos.x86_64                                                          7/10
  Cleanup    : MariaDB-compat-10.1.34-1.el7.centos.x86_64                                                          8/10
  Cleanup    : MariaDB-shared-10.1.34-1.el7.centos.x86_64                                                          9/10
  Cleanup    : MariaDB-common-10.1.34-1.el7.centos.x86_64                                                         10/10
  Verifying  : MariaDB-devel-10.2.16-1.el7.centos.x86_64                                                           1/10
  Verifying  : MariaDB-common-10.2.16-1.el7.centos.x86_64                                                          2/10
  Verifying  : MariaDB-shared-10.2.16-1.el7.centos.x86_64                                                          3/10
  Verifying  : MariaDB-compat-10.2.16-1.el7.centos.x86_64                                                          4/10
  Verifying  : MariaDB-client-10.2.16-1.el7.centos.x86_64                                                          5/10
  Verifying  : MariaDB-common-10.1.34-1.el7.centos.x86_64                                                          6/10
  Verifying  : MariaDB-devel-10.1.34-1.el7.centos.x86_64                                                           7/10
  Verifying  : MariaDB-compat-10.1.34-1.el7.centos.x86_64                                                          8/10
  Verifying  : MariaDB-shared-10.1.34-1.el7.centos.x86_64                                                          9/10
  Verifying  : MariaDB-client-10.1.34-1.el7.centos.x86_64                                                         10/10

Updated:
  MariaDB-client.x86_64 0:10.2.16-1.el7.centos               MariaDB-common.x86_64 0:10.2.16-1.el7.centos
  MariaDB-compat.x86_64 0:10.2.16-1.el7.centos               MariaDB-devel.x86_64 0:10.2.16-1.el7.centos
  MariaDB-shared.x86_64 0:10.2.16-1.el7.centos

Complete!
[root@server ~]#

MariaDB-server以外のrpmパッケージをアップデートします。この方法ですと依存関係で悩まずに済みます。オレ流のやり方なので不具合があっても保証はしません。心配な方は公式サイトにある推奨方法で作業することをオススメします(依存関係をどう処理するか?頭を悩ませながら…ね)。

[root@server ~]# systemctl start mariadb
[root@server ~]# mysql_upgrade -u root -p
Enter password:
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.column_stats                                 OK
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.gtid_slave_pos                               OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.index_stats                                  OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.roles_mapping                                OK
mysql.servers                                      OK
mysql.table_stats                                  OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Phase 2/7: Installing used storage engines... Skipped
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
WARNING: NULL values of the 'db_collation' column ('mysql.proc' table) have been updated with default values. Please verify if necessary.
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
wordpress
wordpress.wp_commentmeta                    OK
wordpress.wp_comments                       OK
wordpress.wp_ewwwio_images                  OK
wordpress.wp_links                          OK
wordpress.wp_lrgawidget_global_settings     OK
wordpress.wp_options                        OK
wordpress.wp_postmeta                       OK
wordpress.wp_posts                          OK
wordpress.wp_siteguard_history              OK
wordpress.wp_siteguard_login                OK
wordpress.wp_term_relationships             OK
wordpress.wp_term_taxonomy                  OK
wordpress.wp_termmeta                       OK
wordpress.wp_terms                          OK
wordpress.wp_usermeta                       OK
wordpress.wp_users                          OK
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
[root@server ~]#

MariaDB-serverを起動して、”mysql_upgrade”コマンドでデータベースのアップグレードを行います。あとはWordPressやphpMyAdminなどのWebAppから正常にアクセス出来ることを確認できたら、アップグレードは終了です。お疲れ様でした。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA