LoginSignup
6
3

More than 3 years have passed since last update.

Censos8にMySQLを入れてみる

Last updated at Posted at 2020-02-20

Centos8にいろいろ入れてみるシリーズ。
今回はMySQL8.0をインストールする方法を記載します。

1.インストール

1.1 AppStreamからインストール

Centos8からは、AppStreamからMySQLをインストールできるようになりました。
AppStreamはデフォルトで入っているリポジトリなので、MySQLのインストールもさくっと終えられるようになっています。

1.1.1 MySQLのインストール

以下のコマンドを実行1するだけです。

$ sudo dnf -y install @mysql:8.0/server

1.2 MySQL Yumリポジトリからインストール

毎度おなじみ、MySQL公式のリポジトリを利用したインストール方法です。
AppStreamより最新バージョンが利用できるようですので、こちらを利用するのも手です。

公式のインストール手順はこちらです。

Yumリポジトリはこちらから手に入れましょう。
本記事ではmysql80-community-release-el8-1.noarch.rpmを利用します。

1.2.1 MySQL Yumリポジトリのインストール

まずはMySQL公式からYumリポジトリをインストールします。

$ sudo dnf -y localinstall https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

Yumリポジトリが正常に追加されたことを確認します。

$ sudo dnf repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community MySQL Connectors Community                         42
mysql-tools-community      MySQL Tools Community                              19
mysql80-community          MySQL 8.0 Community Server                         31

1.2.2 MySQLのモジュールストリームの無効化

mysqlのモジュールストリームを無効化します。
これを実施しないと、mysql-community-*-debuginfoパッケージがしか表示されません。

$ sudo dnf -y module disable mysql

1.2.3 MySQLのインストール

mysql-community-serverが表示されるのを確認してから、

$ sudo dnf search mysql-community-server
====================================== 名前 完全一致: mysql-community-server =======================================
mysql-community-server.x86_64 : A very fast and reliable SQL database server

MySQLをインストールします。

$ sudo dnf -y install mysql-community-server

2.事後設定

2.1 サービス起動&自動起動設定

インストールが完了したら、サービスを起動しましょう。
自動起動の設定も忘れずに。

$ sudo systemctl start mysqld
$ sudo systemctl enable mysqld

2.2 rootユーザ初期パスワード確認 (MySQL Yumリポジトリによるインストールのみ)

rootユーザの初期パスワードを/var/log/mysqld.logから確認します。

$ sudo grep 'temporary password' /var/log/mysqld.log
2020-02-20T06:24:44.514163Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ************

なお、AppStreamからインストールした場合は、rootユーザの初期パスワードは設定されていませんのでご注意ください。

2.3 mysql_secure_installationによる初期設定

mysql_secure_installationを利用して、MySQLの初期設定を行います。

$ mysql_secure_installation

2.3.1 AppStreamでMySQLをインストールした場合

最初に「VALIDATE PASSWORD COMPONENT」をセットアップのセットアップ有無を聞かれます。
今回は設定するため、Yで返答します。
※不要であればN返答でもOKです。

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

「VALIDATE PASSWORD COMPONENT」をセットアップします。
パスワードポリシーを聞かれるので、適切なポリシーを設定します。

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

rootユーザの新しいパスワードを設定します。

Please set the password for root here.

New password: ********

Re-enter new password: ********

パスワードの推定強度とともに、先ほど入力したパスワードで続行するか聞かれます。
問題がなければ、Yで返答します。

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

2.3.2 MySQL YumリポジトリでMySQLをインストールした場合

最初にrootの初期パスワードを求められます。
2.2 rootユーザ初期パスワード確認」で確認した初期パスワードを入力します。

Enter password for user root: ********

rootユーザの新しいパスワードを入力します。

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

New password: ********

Re-enter new password: ********

「validate_password」コンポーネントがインストールされているため、これ以降はコンポーネントの構成にそって実行されます。
そのため、今しがた設定したrootユーザのパスワードを変更するかの確認があります。
ですが、新しいパスワード設定の際にコンポーネントの構成にそったパスワードを入力しないと怒られたしたので、Nで返答します。

The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
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) : n

2.3.3 ここから共通手順となります。

匿名ユーザは不要のため、削除します。

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) : y
Success.

rootユーザのリモートログインは拒否します。

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) : 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? (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!

All done!と表示されれば、初期設定は完了です。

お疲れ様でした。


  1. $ sudo dnf -y install @mysqlと省略してもよいですが、その場合はデフォルト値が採用されるので、$ sudo dnf module list mysqlで事前に確認しておきましょう。 

6
3
2

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
6
3