永遠のプログラマ☆

高齢者でもプログラマ(4x年)

CentOS7 mysql 5.7.25 root パスワード不明でハマる☆

こんにちは。

久しぶりに、CentOS7.3 で mysql をセットアップ。

root パスワードがわからずハマッた。。。。

 

手順は、こちら。

まずインストール。

1. mariadbの削除

# yum remove mariadb-libs

2. MySQL 公式 yum リポジトリの追加
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

3.最新版インストール

MySQL5.7の最新バージョン

# yum --enablerepo=mysql57-community install mysql-community-server

 

4.mysqlサービス起動

# systemctl enable mysqld.service

 

5.  初期パスワードを MySQL のログファイルで探す

/var/log/mysqld.log は、サイズ 0 のまま。

ログインをトライしても同じ。

 

以前は、以下のようなログでパスワードが出てた。。。

2018-05-15T05:33:35.310243Z 1 [Note] A temporary password is generated for root@localhost: #7uYJ/c66:Mw

 

初期パスワードわからん。

パニック。

 

ググったら出てきました。
■パスワードを忘れた場合
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

# systemctl start mysqld.service

# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 MySQL Community Server (GPL)

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> update mysql.user set authentication_string = PASSWORD('MyNewPassword') where user = 'root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

# systemctl stop mysqld.service

# systemctl unset-environment MYSQLD_OPTS
 

めでたしめでたし。