1
2

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.

MySQLのrootパスワード忘れ時のリセット対応方法

Posted at

2つ方法があることを知ったのでメモ書き
下記の1の方法しか知らなかった。

1.skip-grant-tablesオプションを使う
--skip-networkingをするとなお良し

mysqld --skip-grant-tables --skip-networking --user=mysql &

MySQLサーバーにログイン後、FLUSH PRIVILEGESをして、ALTER USERする。FLUSH しないとエラーになる

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

2.init-fileオプションを使う
使用したinit-fileは削除する

mysqld --init-file=/path/to/init --user=mysql &で起動する。

initファイルの中身は

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

5.7.5から前のバージョンだと以下のコマンド

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?