0
0

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のルートパスを忘れてしまったときの対処法

Posted at

目的

MySQLのルートパスを忘れてしまい、認証できなくなったときの対処方法をまとめておく。(よく忘れるので)

概要

①起動しているMySQLを止める
②セーフモードでMySQLを起動
③パスワードを再設定する
④セーフモードのMySQLを止める
⑤通常のMySQLを起動する

手順1 起動しているMySQLを止める

(すでに停止している場合は不要です。)

sudo service mysqld stop

手順2 セーフモードでMySQLを起動

# セーフモードで起動
mysqld_safe --skip-grant-tables & 
# セーフモードのMySQLにrootユーザーでログイン
sudo mysql -u root

手順3 パスワードを再設定する

# パスワード更新のクエリを実行
use mysql;
update user set password=PASSWORD("新しいパスワード") where User='root';
flush privileges;
# ログアウトする
quit

手順4 セーフモードのMySQLを止める

sudo service mysqld stop

手順5 通常のMySQLを起動する

sudo service mysqld start

以上でパスワードの再設定は完了です!
最後まで読んでいただきありがとうございました!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?