MySQL 8.4以降では、長年使われてきた古い認証方式(mysql_native_password)がデフォルトで無効化され、よりセキュアな caching_sha2_password が標準となっています。そのため、設定ファイル(mysqld.cnf)を書き換えて旧プラグインを強制する手順は不要となり、標準の認証方式のまま初期設定を進めます。
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
''のpasswordは任意の、強固なものを入力ください。
標準推奨の caching_sha2_password を用いて強固なパスワードを設定します。
flush privileges;
exit
mysql_secure_installation
sudo mysql_secure_installation
質問事項
Enter password for user root: # 上記で設定したパスワードを入力します VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: # パスワード強度チェックを有効にするためYを入力してEnter There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: # ポリシーに合わせて0/1/2を入力(ローカル開発環境なら0または1を推奨) Estimated strength of the password: 50 Change the password for root ? ((Press y|Y for Yes, any other key for No) : # 既に直前の手順でパスワードを設定済みのため、ここではnを選択します。 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : # anonymousユーザーを削除するためY Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : # rootユーザのリモートログインを禁止するためY Remove test database and access to it? (Press y|Y for Yes, any other key for No) : # テストDBを削除するためY Reload privilege tables now? (Press y|Y for Yes, any other key for No) : # 設定を反映するためY
SELECT
table_schema AS 'データベース名',
SUM(data_length + index_length) AS '合計サイズ(バイト)',
SUM(data_length) AS 'データサイズ(バイト)',
SUM(index_length) AS 'インデックスサイズ(バイト)',
-- 人が読みやすいようにメガバイト(MB)やギガバイト(GB)でも表示
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '合計サイズ(MB)',
ROUND(SUM(data_length) / 1024 / 1024 / 1024, 2) AS '合計サイズ(GB)'
FROM
information_schema.TABLES
WHERE
table_schema = '調べたいデータベース名' -- ここにサイズを知りたいデータベース名を入力してください
GROUP BY
table_schema;
SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' CONVERT TO CHARACTER SET utf8mb4 COLLATE ', @COLLATE, ';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = @DATABASE_NAME
AND TABLE_TYPE = 'BASE TABLE';
MySQLから抜ける
EXIT
メンテナンスモードの解除を実行
Nextcloudのルートディレクトリ移動
cd /var/www/html/nextcloud && pwd
自分の環境に合わせます。(筆者環境/home/www-data/nextcloud)
メンテナンスモード無効化
sudo -u www-data php occ maintenance:mode --off
メンテナンスモード確認
運用中のNextcloudのURLにアクセスし、普通にアクセスできることを確認します。
切り戻し
何か不具合があった場合の切り戻し手順です。上記、メンテナンスモードを有効化してから行ってください。
バックアップしたDBがあることを再確認する
ls -l /hoge/nextcloud_backup.$(date +%Y%m%d).sql
バックアップを行ったディレクトリを指定します。
head -100 /hoge/nextcloud_backup.$(date +%Y%m%d).sql
ファイルがあること、平文で読めることを確認します。
管理者権限でMySQLにログインする
mysql -u root -p
対象のDBを確認する
SHOW DATABASES;
nextcloudが動いているDBであることを再確認してください。
不具合が発生したDBを削除する
二回ほど深呼吸して、落ち着いて作業しましょう。
DROP DATABASE nextcloud;
DBを再作成する
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
MySQLから抜ける
EXIT
DB復元
mysql -h localhost -u nextcloud -p nextcloud < /hoge/nextcloud_backup.$(date +%Y%m%d).sql