AC-5

某SEの雑記帳

MySQL初期設定

      2015/06/25

初回起動

MySQL5.6をインストールして始めて起動すると、以下のようなメッセージが表示されます。

[root@test]# service mysqld start←MySQL起動
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h centos65 password 'new-password'

Alternatively you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.
...

ここでは次の2つを行った方が良いという事が記載されています。

1.rootユーザーのパスワードを設定する
2.mysql_secure_installationを実行する

rootユーザーのパスワード変更

MySQL5.6をインストールした初期状態では、管理者となるrootパスワードが設定されていないため、先ほどのメッセージで表示された
/usr/bin/mysqladmin -u root password ‘new-password’
でパスワードを設定する事ができます(この例だと「new-password」が新しく設定するパスワードになります。)

[root@test]# /usr/bin/mysqladmin -u root password 'new-password'←MySQLパスワード変更

mysql_secure_installation

次にこのmysql_secure_installationを利用してセキュリティ要件を設定します。

このコマンドでは次の設定が行えます。

・root ユーザーパスワードの変更
・anonymous ユーザーの削除
・リモートホストから root ユーザーでログインするのを禁止する
・testデータベースの削除 (存在する場合)

このスクリプトでもrootのパスワードを変更するかを聞いてくれます。
既に変更していれば今回は変更する必要はありません。
初期状態ではanonymousという匿名ユーザが作成されていますが、安全でない為削除します。
基本的には同じサーバー内でプログラムからMySQLへ接続を行うので、リモートホストからの接続も禁止します。
初期状態に入っているtestというデータベースを削除します。

実際には対話式ですので、Yes(Y)かNo(N)で返答していきます。

[root@test]# /usr/bin/mysql_secure_installation←スクリプト実行
...
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] n←先ほどrootパスワードを変更していればn
… skipping.

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? [Y/n] Y←anonymousを削除
… 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? [Y/n] Y←リモートからの接続を拒否
… 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? [Y/n] Y←テストデータベースを削除
– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– 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? [Y/n] Y←テーブルをリロード
… Success!

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up…

以上で初期設定は終了です。

 - Linux