2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7でMySQL5.7のパスワードリセット

Posted at

MySQLが異常終了した際に何故か今まで出来ていたログイン方法では接続ができなくなってしまった際に対応した際のメモ。rootです。

mysql_secure_installationで設定したパスワードや初期パスワードでも以下のエラーになった。

ERROR 1045 (28000): Access denied for user

Change mysql root password on Centos7

オプションを設定して起動

systemctl stop mysqld

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

systemctl start mysqld

mysql -u root

更新

UPDATE mysql.user SET authentication_string = PASSWORD('再設定するパスワード') WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit

更新(5.7.6以降では以下を推奨)

ALTER USER 'root'@'localhost' IDENTIFIED BY '再設定するパスワード';
exit

オプションをクリアして起動

systemctl stop mysqld

systemctl unset-environment MYSQLD_OPTS

systemctl start mysqld
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?