プロジェクト

全般

プロフィール

mysql_secure_installationがうまくいきません。

手動人形
Added 2023/02/09 ago

ネット上の記事などでMySQLインストール時に設定が推奨されるmysql_secure_installation。

バージョンアップによって、以下の手順が必要になりました。

確認した環境

  • Ubuntu 20.04 LTS
  • MySQL 8.0.32

mysql設定変更

sudo mkdir /etc/old
# 各種設定ファイルのバックアップをここに格納します。

sudo cp -pi /etc/mysql/mysql.conf.d/mysqld.cnf /etc/old/mysqld.cnf.$(date +%Y%m%d)
# .$(date +%Y%m%d)をつけることで、バックアップファイルは当日日付(YYYYMMDD形式)で記録されます

diff -u /etc/mysql/mysql.conf.d/mysqld.cnf /etc/old/mysqld.cnf.$(date +%Y%m%d)
# バックアップが取れていることを「差分が存在しないこと」で確認します

echo -e "default_authentication_plugin=mysql_native_password" | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
# mysqld.cnfに追記をします

設定後の差分確認

diff -u /etc/old/mysqld.cnf.$(date +%Y%m%d) /etc/mysql/mysql.conf.d/mysqld.cnf
+default_authentication_plugin=mysql_native_password

設定反映

sudo systemctl restart mysql.service

mysql rootパスワード変更

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
#''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を入力

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

以上でMySQLの初期設定は完了です。

トップへ
クリップボードから画像を追加 (サイズの上限: 50 MB)