LoginSignup
5
5

More than 5 years have passed since last update.

MySQLのrootパスワードを忘れたときの対処法

Last updated at Posted at 2014-01-05

MySQL徹底入門 第3版 ~5.5新機能対応~MySQL徹底入門 第3版 ~5.5新機能対応~

フラフラの時にインストールしたMySQLのrootパスワードを忘れてしまった!困った!と慌てた場合に、対処する方法。そんなに難しくない。

一応、CentOS 6.xで確認。
Ubuntu でも同じなんじゃないかな~

 

まず、root権限になる。

sudo su -password:

次に、mysqld を落とす。平和的に。

# /etc/init.d/mysql stop

強引に落とす場合は、

# killall mysqld

セーフモードでmysqlを立ち上げる。

# /usr/bin/mysqld_safe --user=root --skip-grant-tables

これで、パスワードナシでmysqlにアクセス出来るので、パスワード初期化

# mysqlmysql> update user set Password=null where Host='localhost' and User='root';
mysql> exit

次に、セーフモードではなく通常モードでmysqldを再起動

# /etc/init.d/mysql restart

mysqlにrootでログインしてパスワードを設定する。

# mysql -u rootmysql> set password for root@localhost=password('rootパスワード');

再設定完了!

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