UbuntuでMySQLを8.0.34から8.1.0へアップグレード。Innovation Releaseを使う設定。

MySQL

背景

  • 2023年7月18日 (今から約1ヶ月前)にMySQL初のInnovation Releaseが行われました。バージョンは8.1.0です。

最近のアップデート

あんまりMySQLの最新情報をキャッチアップしていなかったので軽くまとめます。

リリースサイクルの変更

2023年7月19日の記事にあるようにMySQLのリリースサイクルが変更になりました。

https://blogs.oracle.com/mysql-jp/post/introducing-mysql-innovation-and-longterm-support-lts-versions-jp

今後のリリースはLTSとInnovation Releaseの2つになります。Ubuntuと同じようなリリース体系を取ることとなります。バージョン表記は今までと変わらずセマンティックバージョニングでの表記になります。

Innovation Releaseは1月ごとにマイナーバージョンが1つ上がります。LTSは2年に1回マイナーバージョンが上がります。よって、2年に1回はInnovation ReleseとLTSのバージョンが合致します。

そして、LTSの方のバージョンはマイナーバージョン12個ずつ上がっていきます。Innovation Releaseのマイナーバージョンに関しては12で繰り上がり、メジャーバージョンが1つ上がるみたいです。(最初の方はイレギュラーにインクリメントされそうです)

よって、LTSのバージョンは8.4.0, 9.7.0, 10.7.0….という具合に上がっていきます。(非常に分かりづらい。

LTSに対してパッチが当たるとリビジョンがインクリメントされます。

https://blogs.oracle.com/mysql-jp/post/introducing-mysql-innovation-and-longterm-support-lts-versions-jp

MySQL8のバージョン樹形図

@yoku0825さんのスライドにあるこの樹形図は参考になります。

https://speakerdeck.com/yoku0825/bokutatihamysql-8-dot-1todousheng-kiruka?slide=25

mysqlshのバージョン

mysqlshにはmysql serverのバージョンとは関係なく新機能をどんどん取り入れていくようです。言い換えると、Innovation Releaseと同じスパンで更新されていくような事を言ってました。

LTS or Innovation Release

ということで、業務や個人開発においてLTSか、Innovation Releaseのどちらを使うかが迷います。

個人的には、数ヶ月に1回ぐらい追加機能が入るような感じが良かったので3ヶ月1回にリリースされるInnovation Releaseのストリームをトラッキングすることとします。LTSは2年スパンです。

特に、MySQLは8.0になってからクリティカルなバグがリリースされる事件が数回起こっています。(過去、このバグを踏んで痛い目を見ました)

業務はLTS、個人開発はInnovation Releaseで良いのかなと思ってます。OSのディストリビューションをLTSにするかしないかという意思決定と揃えるとポリシーが揃ってわかりやすいと思います。

UbuntuのLTSのリリースも2年スパンなのでMySQLと同様です。Ubuntuは1年毎にメジャーバージョンが上がるので、偶数はLTSを意味することになります。

Innovation Releaseも日々使っておいてキャッチアップすることも重要なので個人サービスや自宅サーバはInnovation Releaseを使っていきます。OSもUbuntu Serverの最新を使うようにしているのでポリシー的にも合致します。

MySQL 8.1へのアップグレード事前チェック

まずは、現在のMySQL Serverのバージョンを調べてみます。

root@localhost:test> select @@version;
+-------------------------+
| @@version               |
+-------------------------+
| 8.0.34-0ubuntu0.22.04.1 |
+-------------------------+
1 row in set (0.00 sec)

MySQL Serverのapt lineはdebパッケージよって提供されています。このパッケージを入れることで自分が使いたいMySQLのメインストリームとなるLTSまたはInnovation Releaseのapt lineが追加されます。

% wget https://dev.mysql.com/get/mysql-apt-config_0.8.26-1_all.deb
% sudo dpkg -i mysql-apt-config_0.8.26-1_all.deb

インストール中に以下のようなダイアログが立ち上がり、どのプロダクトを使いたいかを選択します。デフォルトではLTSになっています。

なので、mysql-innovationを選びます。

画面を戻ったら、更新されています。OKを押して完了します。

まずは、最近(と言っても数年前から)のトレンドであるmysqlshをインストールします。mysqlクライアントの高機能版です。JavaScriptのsyntaxでコマンドを発行できるし、管理機能が充実しています。

matsu@dell ~> sudo apt-get update
matsu@dell ~> sudo apt-get install mysql-shell
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  mysql-shell
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 26.5 MB of archives.
After this operation, 226 MB of additional disk space will be used.
Get:1 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-shell amd64 8.1.1-1ubuntu22.04 [26.
5 MB]
Fetched 26.5 MB in 5s (5739 kB/s)
selecting previously unselected package mysql-shell:amd64.
Reading database ... 158313 files and directories currently installed.)
Preparing to unpack .../mysql-shell_8.1.1-1ubuntu22.04_amd64.deb ...
Unpacking mysql-shell:amd64 (8.1.1-1ubuntu22.04) ...
Setting up mysql-shell:amd64 (8.1.1-1ubuntu22.04) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
matsu@dell ~>

とりあえず、バックアップをします。mysqlshを立ち上げて、以下のコマンドでdumpを行います。今までのmysqldumpに比べると超速いです。

util.dumpInstance("/home/matsu/20230828")

実行結果

matsu@dell ~> mysqlsh --user=root -p
Cannot set LC_ALL to locale en_US.UTF-8: No such file or directory
MySQL Shell 8.1.1

Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@localhost'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 29696 (X protocol)
Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu)
No default schema selected; type \use <schema> to set one.
 MySQL  localhost:33060+ ssl  JS > util.dumpInstance("/home/matsu/20230828")
Acquiring global read lock
Global read lock acquired
Initializing - done
2 out of 6 schemas will be dumped and within them 54 tables, 0 views.
3 out of 6 users will be dumped.
Gathering information - done
All transactions have been started
Locking instance for backup
Global read lock has been released
Writing global DDL files
Writing users DDL
Running data dump using 4 threads.
NOTE: Progress information uses estimated values and may not be accurate.
NOTE: Table statistics not available for `matsu_blog_covid19`.`wp_cocoon_affiliate_tags`, chunking operation may be not optimal. Please consider running 'ANALYZE TABLE `matsu_blog_covid19`.`wp_cocoon_affiliate_tags`;' f
irst.
NOTE: Table statistics not available for `matsu_blog_covid19`.`wp_cocoon_function_texts`, chunking operation may be not optimal. Please consider running 'ANALYZE TABLE `matsu_blog_covid19`.`wp_cocoon_function_texts`;' f
irst.
NOTE: Table statistics not available for `matsu_blog_covid19`.`wp_users`, chunking operation may be not optimal. Please consider running 'ANALYZE TABLE `matsu_blog_covid19`.`wp_users`;' first.
<snip>
Writing schema metadata - done
Writing DDL - done
Writing table metadata - done
Starting data dump
<snip>
Dump duration: 00:00:12s
Total duration: 00:00:12s
Schemas dumped: 2
Tables dumped: 54
Uncompressed data size: 1.59 GB
Compressed data size: 559.63 MB
Compression ratio: 2.8
Rows written: 4009346
Bytes written: 559.63 MB
Average uncompressed throughput: 129.15 MB/s
Average compressed throughput: 45.34 MB/s
 MySQL  localhost:33060+ ssl  JS >

圧縮後500MBのデータが12秒でdumpできました。

matsu@dell ~> du -hs  20230828/
535M    20230828/

次に、MySQL 8.1をインストールします。

本当はここでアップグレードの互換性チェックを行うべきです。この記事の下の方に記載してあります。

まずは、apt-cache policy mysql-serverコマンドで、どのパッケージが使われるかをチェックしてみます。

Ubuntuの8.0がインストール済みですが、8.1が入る事がわかります。

matsu@dell ~> apt-cache policy mysql-server
mysql-server:
  Installed: 8.0.34-0ubuntu0.22.04.1
  Candidate: 8.1.0-1ubuntu22.04
  Version table:
     8.1.0-1ubuntu22.04 500
        500 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 Packages
 *** 8.0.34-0ubuntu0.22.04.1 500
        500 http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu jammy-updates/main amd64 Packages
        500 http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu jammy-security/main amd64 Packages
        100 /var/lib/dpkg/status
     8.0.28-0ubuntu4 500
        500 http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu jammy/main amd64 Packages
matsu@dell ~>

ということで、インストール(アップグレード)します。

sudo apt install mysql-client mysql-server

matsu@dell ~> sudo apt install mysql-client mysql-server                                                                                                                                                           [62/674]
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl
  libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libprotobuf-lite23 libtimedate-perl liburi-perl
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core
The following packages will be REMOVED:
  mysql-client-8.0 mysql-client-core-8.0 mysql-server-8.0 mysql-server-core-8.0
The following NEW packages will be installed:
  mysql-client mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core
The following packages will be upgraded:
  mysql-common mysql-server
2 upgraded, 6 newly installed, 4 to remove and 0 not upgraded.
Need to get 31.0 MB of archives.
After this operation, 33.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-server amd64 8.1.0-1ubuntu22.04 [66.5 kB]
Get:2 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-common amd64 8.1.0-1ubuntu22.04 [67.8 kB]
Get:3 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-community-client-plugins amd64 8.1.0-1ubuntu22.04 [1428 kB]
Get:4 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-community-client-core amd64 8.1.0-1ubuntu22.04 [2087 kB]
Get:5 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-community-client amd64 8.1.0-1ubuntu22.04 [2407 kB]
Get:6 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-client amd64 8.1.0-1ubuntu22.04 [66.5 kB]
Get:7 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-community-server-core amd64 8.1.0-1ubuntu22.04 [24.8 MB]
Get:8 http://repo.mysql.com/apt/ubuntu jammy/mysql-innovation amd64 mysql-community-server amd64 8.1.0-1ubuntu22.04 [78.2 kB]
Fetched 31.0 MB in 7s (4296 kB/s)
Preconfiguring packages ...
(Reading database ... 169877 files and directories currently installed.)
Preparing to unpack .../mysql-server_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-server (8.1.0-1ubuntu22.04) over (8.0.34-0ubuntu0.22.04.1) ...
(Reading database ... 169880 files and directories currently installed.)
Removing mysql-server-8.0 (8.0.34-0ubuntu0.22.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Removing mysql-client-8.0 (8.0.34-0ubuntu0.22.04.1) ...
Removing mysql-client-core-8.0 (8.0.34-0ubuntu0.22.04.1) ...
Removing mysql-server-core-8.0 (8.0.34-0ubuntu0.22.04.1) ...
(Reading database ... 169679 files and directories currently installed.)
Preparing to unpack .../0-mysql-common_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-common (8.1.0-1ubuntu22.04) over (5.8+1.0.8) ...
Selecting previously unselected package mysql-community-client-plugins.
Preparing to unpack .../1-mysql-community-client-plugins_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client-plugins (8.1.0-1ubuntu22.04) ...
Selecting previously unselected package mysql-community-client-core.
Preparing to unpack .../2-mysql-community-client-core_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client-core (8.1.0-1ubuntu22.04) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack .../3-mysql-community-client_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-client (8.1.0-1ubuntu22.04) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../4-mysql-client_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-client (8.1.0-1ubuntu22.04) ...
Selecting previously unselected package mysql-community-server-core.
Preparing to unpack .../5-mysql-community-server-core_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-server-core (8.1.0-1ubuntu22.04) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack .../6-mysql-community-server_8.1.0-1ubuntu22.04_amd64.deb ...
Unpacking mysql-community-server (8.1.0-1ubuntu22.04) ...
Setting up mysql-common (8.1.0-1ubuntu22.04) ...
Installing new version of config file /etc/mysql/conf.d/mysql.cnf ...                                                                                                                                               [5/678]
Installing new version of config file /etc/mysql/my.cnf.fallback ...
Setting up mysql-community-server-core (8.1.0-1ubuntu22.04) ...
Setting up mysql-community-client-plugins (8.1.0-1ubuntu22.04) ...
Setting up mysql-community-client-core (8.1.0-1ubuntu22.04) ...
Setting up mysql-community-client (8.1.0-1ubuntu22.04) ...
Setting up mysql-client (8.1.0-1ubuntu22.04) ...
Setting up mysql-community-server (8.1.0-1ubuntu22.04) ...
Installing new version of config file /etc/apparmor.d/usr.sbin.mysqld ...
Installing new version of config file /etc/mysql/mysql.cnf ...
Installing new version of config file /etc/mysql/mysql.conf.d/mysqld.cnf ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-server (8.1.0-1ubuntu22.04) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...

The processor microcode seems to be up-to-date.

Restarting services...
Service restarts being deferred:
 systemctl restart NetworkManager.service
 systemctl restart networkd-dispatcher.service
 systemctl restart unattended-upgrades.service
 systemctl restart wpa_supplicant.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
matsu@dell ~>

インストール中に、以下のダイアログが表示されました。稼働中のサービスから接続できなくなるリスクを排除するために、互換性を優先して下を選びました。

チェック

ちゃんとインストールが完了したかをチェックします。

まずは、パッケージが入っているかをチェックしてみます。

dpkg -l|grep mysql

matsu@dell ~> dpkg -l|grep mysql
ii  mysql-apt-config                      0.8.26-1                                     all          Auto configuration for MySQL APT Repo.
ii  mysql-client                          8.1.0-1ubuntu22.04                           amd64        MySQL Client meta package depending on latest version
ii  mysql-common                          8.1.0-1ubuntu22.04                           amd64        Common files shared between packages
ii  mysql-community-client                8.1.0-1ubuntu22.04                           amd64        MySQL Client
ii  mysql-community-client-core           8.1.0-1ubuntu22.04                           amd64        MySQL Client Core Binaries
ii  mysql-community-client-plugins        8.1.0-1ubuntu22.04                           amd64        MySQL Client plugin
ii  mysql-community-server                8.1.0-1ubuntu22.04                           amd64        MySQL Server
ii  mysql-community-server-core           8.1.0-1ubuntu22.04                           amd64        MySQL Server Core Binaires
ii  mysql-server                          8.1.0-1ubuntu22.04                           amd64        MySQL Server meta package depending on latest version
rc  mysql-server-8.0                      8.0.34-0ubuntu0.22.04.1                      amd64        MySQL database server binaries and system database setup
ii  mysql-shell:amd64                     8.1.1-1ubuntu22.04                           amd64        MySQL Shell (part of MySQL Server) 8.0
rc  php8.0-mysql                          8.0.8-1ubuntu0.3                             amd64        MySQL module for PHP
rc  php8.1-mysql                          8.1.2-1ubuntu2.11                            amd64        MySQL module for PHP
ii  php8.2-mysql                          8.2.9-1+ubuntu22.04.1+deb.sury.org+1         amd64        MySQL module for PHP

ちゃんとmysql-server 8.1がインストールされていそうです。

動いているサーバがMySQL 8.1かをチェック

早速mysqlshを使って検証してみます。

\sql
SELECT @@version;

番外編: データのアップグレードができるかチェック

本当はアップグレード前にやるべきでしたが、mysql-serverのバージョンアップに当たって問題がないかをチェックするコマンドの紹介です。

util.checkForServerUpgrade();

番外編: mysqlsh

mysqlshの使い方は\helpと入力するととても長い説明が表示されますが、一通り読んでおくのが良いと思います。いろいろできるので。

backup & recoveryに関しては以下の記事が詳しいです。

MySQL Shell Dump UtilityとDump Loading Utilityの使い方 - Qiita
Oracle MySQL Database Serviceの使い方メモ〜番外編その3MySQL Shell Dump Utility / Dump Loading Utilityボリュームが多…

まとめ

  • 数年ぶりにMySQLをキャッチアップ。。。。
  • MySQL Heatwaveはすごそう。場合によってはSnowflakeより速いらしい。アーキテクチャはAuroraって感じ。Snowflakeも似たようなものだだし最近のRDBの水平分割の流行りの形ぽい。
  • MySQL Clusterの構築、運用が格段に楽になっているっぽい。Oracleに買収されて、Oracleの得意としている堅牢性を注入した感じがします。

コメント