CentOS7にMySQL5.7をインストール&ログイン

# MySQLのインストール
MySQL 公式の yum リポジトリを追加した後、インストール

```
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

# yum info mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
mysql-connectors-community                                                                                                                               | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                    | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                        | 2.5 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                                                                                      |  49 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                                                                                           |  66 kB  00:00:00     
(3/3): mysql57-community/x86_64/primary_db                                                                                                               | 190 kB  00:00:00     
Available Packages
Name        : mysql-community-server
Arch        : x86_64
Version     : 5.7.28
Release     : 1.el7
Size        : 199 M
Repo        : mysql57-community/x86_64
Summary     : A very fast and reliable SQL database server
URL         : http://www.mysql.com/
License     : Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Description : （以下省略）

# yum -y install mysql-community-server
```

MySQLのバージョン確認

```
# mysqld --version
mysqld  Ver 5.7.28 for Linux on x86_64 (MySQL Community Server (GPL))
```

MySQLサービスを起動、停止してみる

```
# systemctl start mysqld
# systemctl status mysqld
```

初回起動時にrootユーザの一時パスワードが作成され、以下のログファイルに出力される
※以下のパスワードは例です

```
# cat /var/log/mysqld.log  | grep password
2019-10-30T15:57:02.866797Z 1 [Note] A temporary password is generated for root@localhost: lyo6Vv(N5tMe
```

#初回ログイン
MySQLにログインしてみる

```
# mysql -u root -h localhost -p
Enter password:   ←ここで一時パスワードを入力する
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28

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.

mysql> 
mysql> \q
Bye
```

この状態でコマンド実行しようとするとrootのパスワード変更を求められるので、以下の通り変更する

```
mysql> SHOW DATABASES;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Your_passw0rd';
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
```