有馬総一郎のブログ

(彼氏の事情)

2021年01月19日 10:43:01 JST - 3 minute read - Comments - Linux

Nextcloudで使っているMySQLを5.7から8にアップグレードして認証方式をcaching_sha2_passwordにする

Nextcloud 20.0.5にアップグレードすると、MySQL version "5.7.32-0ubuntu0.18.04.1" is used. Nextcloud 21 will no longer support this version and requires MySQL 8 or higher.という警告が出るようになった。

“Nextcloud 21はこのバージョンをサポートしなくなり、MySQL 8以上が必要になります。“ということか。なので、MySQL 5.7から8にアップグレードすることにした。

どうも、PPAにMySQLの最新のリポジリーを追加してインストールするみたいなやり方が見付からなかったので、 mysql-apt-config_バージョン.deb ファイルを落してくる。

MySQL レポジトリファイル置き場

$ wget https://repo.mysql.com/mysql-apt-config_0.8.16-1_all.deb
$ sudo apt install ./mysql-apt-config_0.8.16-1_all.deb

するとMySQLのパッケージツール(apt)での設定を変更する画面となる。

  1. MySQL Server & Cluster (Currently selected: mysql-5.7) を選択して
  2. mysql-8.0 を選択、了解
  3. MySQL Server & Cluster (Currently selected: mysql-8.0) になったことを確認して、OK、了解

mysql-apt-config
mysql-apt-config
mysql-apt-config

Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)

警告: apt-key はスクリプトで使用してはいけません (mysql-apt-config パッケージの postinst maintainerscript から呼び出されます)。

な警告が出たけど、気にしなくていいだろう。パッケージの最新化。

$ sudo apt update

これで、 MySQLが保留(手動アップグレード対象)になったので、アップグレード。

apt-get dist-upgradeとapt-get upgradeの違い - ソースコード備忘録

-sを付けておこなえば、シュミレーションするだけで実行はされない。どんなものが削除、追加されるの分かるので、事前に確認しておく。

$ sudo apt dist-upgrade

途中で、認証プラグインのデフォルトを caching_sha2_password にするか聞かれるので答える。

MySQL8.0新機能 (caching_sha2_password 認証プラグイン) | スマートスタイル TECH BLOG|データベース&クラウドの最新技術情報を配信

  • Use Strong Password Encryption (RECOMMENED) を選択して、了解。
MySQL 8

caching_sha2_password にしたからといって既存ユーザーの認証方式まで自動で変更されるわけではない。

$ mysql -u root -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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 '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
1 row in set (0.03 sec)

mysql> select User, Plugin from mysql.user where User = 'user';
+------------+-----------------+
| User       | Plugin          |
+------------+-----------------+
| user | mysql_native_password |
+------------+-----------------+
1 row in set (0.01 sec)

mysql> quit

切り替え

-- caching_sha2_passwordにする
mysql> ALTER USER user@localhost IDENTIFIED WITH caching_sha2_password BY 'userpassword';
-- mysql_native_passwordに戻す
mysql> ALTER USER user@localhost IDENTIFIED WITH mysql_native_password BY 'userpassword';

旧方式での認証によるユーザーを作成する場合

-- mysql_native_password認証でのユーザーを作成
mysql> CREATE USER user@localhost IDENTIFIED WITH mysql_native_password BY 'userpassword';

さてとこうなってくると俄然、気になっているのは Nextcloud でも対応しているのか?ということだが、phpのバージョンによるみたいだ。

自環境は7.4.14

$ php -v
PHP 7.4.14 (cli) (built: Jan 13 2021 08:04:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies

試しに Nextcloud のユーザーの認証方式を変更したところ。どちらでも問題なく動いた。切り替えのために Nextcloud 側で設定ファイルの変更とかする必要もない。めでたし、めでたし。

Tags: Ubuntu Server Nextcloud MySQL

rxvt-unicodeことurxvtを導入してみる Nextcloudログ周りのメモ

comments powered by Disqus