CentOS7にMySQL5.7インストール

インストール

MySQLのドキュメントを見ながら進める
https://dev.mysql.com/doc/refman/5.6/ja/linux-installation-yum-repo.html

どのパッケージをインストールするか確認

$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

EL7ベースであることがわかるったので以下のページの「No thanks, just start my download.」のURLをコピー
https://dev.mysql.com/downloads/file/?id=470281

リポジトリ追加

$ yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

インストール

$ yum install -y mysql-community-server

# 確認
$ mysqld --version
mysqld  Ver 5.7.21 for Linux on x86_64 (MySQL Community Server (GPL))

初期セットアップ

rootの初期パスワード確認

# grep 'A temporary password is generated for root' /var/log/mysqld.log
2018-03-29T15:10:11.430995Z 1 [Note] A temporary password is generated for root@localhost: kgqO#QbnM86S

パスワードのポリシーを変更
/etc/my.cnf に追記

validate-password=OFF
default_password_lifetime=0

起動

# systemctl start mysqld.service

MySQLに接続して最低限のセットアップは以下のサイトを参考に行なった
https://weblabo.oscasierra.net/mysql-57-init-setup/

mysql_secure_installation メモ

# パスワード変更しない
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No

# anonymousユーザーは削除
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

# リモートからのrootログインも認めない
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

# testデータベースは削除
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

# リロードする
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

作業用ユーザーの作成

$ grant all on *.* to username@localhost identified by '********';

エラーとか

rootで起動するなということらしい

# mysqld start
2018-03-30T02:28:32.878384Z 0 [Note] mysqld (mysqld 5.7.21) starting as process 9771 ...
2018-03-30T02:28:32.893485Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2018-03-30T02:28:32.893811Z 0 [ERROR] Aborting
2018-03-30T02:28:32.894005Z 0 [Note] Binlog end
2018-03-30T02:28:32.894385Z 0 [Note] mysqld: Shutdown complete

rootにパスワードがセットされている

# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

参考
https://weblabo.oscasierra.net/mysql-57-init-setup/