LoginSignup
15
8

More than 3 years have passed since last update.

MySQLのデフォルトパスワードを確認する

Posted at

はじめに

MySQL5.7以降では、デフォルトでrootユーザーのパスワードが自動で初期設定されている。
このパスワードの調べ方のメモ。

環境

OSはAmazonLinux2
MySQLのバージョンは5.7

OS
# cat /etc/system-release
Amazon Linux release 2 (Karoo)

# mysql -V
mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper

MySQLにrootログインしてみる

rootでMySQLに入ろうとすると、Access Diniedとなり弾かれます。

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

MySQLのパスワード確認

rootの初期パスワードを確認する。
初期パスワードは /var/log/mysqld.log に記述されているため、以下のコマンドで確認できる。

パスワード確認
# cat /var/log/mysqld.log | grep password
2019-12-13T06:12:17.402781Z 1 [Note] A temporary password is generated for root@localhost: <初期パスワード>

A temporary password is generated for root@localhost: 以降の文字列が初期パスワード。
この文字列をコピペしてログインすると、MySQLにログインできるようになる。

MySQLにログイン
# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
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> set password for root@localhost='新パスワード';
Query OK, 0 rows affected (0.00 sec)
15
8
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
15
8