61
76

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQL5.7の初期設定まとめ

Posted at

概要

mysql5.7をインストールした後の初期設定をまとめます

rootの初期パスワードを知る

mysql5.7では、インストールした際に、勝手に初期パスワードを設定してくれます。
このパスワードは、/var/log/mysqld.logに下記のように残されてますのでメモっときましょう。

2016-08-24T11:04:56.814466Z 1 [Note] A temporary password is generated for root@localhost: jKu(jQ(<;4Qh

初期設定

mysql_secure_installation というコマンドで、初期設定を行えます
やる事ははシンプルです。

    1. rootのパスワード変更
    1. anonymousの削除
    1. リモートからのrootユーザでのログインの禁止
    1. testデータベースの削除

気をつけないといけないのは、パスワードは公式に記載のある通り、MIDIUMポリシーに沿っている必要があることです。

MEDIUM ポリシーは、パスワードが最低 1 つの数値文字を含み、1 つの小文字および大文字を含み、1 つの特殊文字 (英数字以外) を含む必要があるという条件を追加します。

実際にやってみた

$ mysql_secure_installation

Securing the MySQL server deployment. 

Enter password for user root: "ここで先ほどメモした初期パスワードを入力"

The existing password for the user account root has expired. Please set a new password.

New password: "新しいパスワードを入力"

Re-enter new password:
 ... Failed! Error: Your password does not satisfy the current policy requirements
 
"↑ パスワードのポリシーにそってないと怒られます"

New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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.

"anounymousユーザを消すならy"
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

"リモートからのrootユーザのログインを禁止するならy"
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 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.

"testデータベースを消すならy"
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - 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
Success.

All done!

"さっき登録したパスワードでログインしてみる"
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

mysql>

my.cnfの設定

/etc/my.cnf
## 追加設定

# 文字コードをutf-8に
character-set-server=utf8

# 起動ファイル
datadir=/var/lib/mysql

# ソケット
socket=/var/lib/mysql/mysql.sock

# デフォルトのストレージエンジン
default-storage-engine=InnoDB

## 追加設定
[mysql]

# mysqlの文字コードもutf-8に
default-character-set=utf8

文字コードの設定や、デフォルトのストレージエンジンを設定しときます

mysqldの再起動

$ sudo service mysqld restart
61
76
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
61
76

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?