1. 概要
インストール後に、スクリプトを実行して初期化します。
「MySQL 5.7」以降、初期化時にパスワード等を設定するのが正式な設定方法です。
スクリプトの動きが、「8.0」のときと、少し変わっているようです。
プロンプトが変ですよとか、パスワードのレベルを決めますかというものがなくなりました。
2. mysql_secure_installation
「root」ユーザ権限で。
mysql_secure_installation
以降、プロンプトに従って入力して進めていきます。
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
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:
「VALIDATE PASSWORD」という、パスワード用のモジュールをインストールしますかというのですが。
ここは、面倒なので n Enter で進めます。
Please set the password for root here.
New password:
Re-enter new password:
「root」ユーザのパスワードを求められています。
2回入力します。
エコーバックされませんので、ご注意。
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 users」を削除しますかってんで y Enter
Success.
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 Enter
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
テストデーターベースを削除しますかってんで y Enter
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
権限が変更されたテーブルを再度読み込みますかってんで y Enter
Success.
All done!
これで、基本的な設定は、終わりです。
いったん、サーバを再起動します。
service mysql-server restart
3. root パスワードの設定
「MySQL 5.7」では、「root」のパスワードを変更した場合は、ログインして再度パスワードの設定を行っていました。
そうしないと、
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28-log
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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.
root@localhost [(none)]> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
てな感じで怒られていたのですが、「MySQL 8.1」では、それは、なくなったようです。