MYSQLリセットrootパスワード


1.MYSQLサービスを停止する;
UbuntuまたはDebianで
sudo service mysql stop

または
sudo /etc/init.d/mysql stop

CentOS,Fedora,RHELで:
sudo service mysqld stop

または
sudo /etc/init.d/mysqld stop

2.安全モードに入る
sudo mysqld_safe --skip-grant-tables &


PS:最後の&号があります
このような情報が表示されるかもしれません.
mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.

mysqld_safe Logging to '/var/log/mysql/error.log'.

mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

これらの類似情報が表示されたら、CTRL+Cを押して終了し、次のステップに進みます.NOTES: , , ,
mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.

mysqld_safe Logging to '/var/log/mysql/error.log'.

mysqld_safe A mysqld process already exists
mysql
ps uaxww | grep -i mysql

見つかったらkillでプロセスを終了し、もう一度やり直します.
3.空のパスワードでログイン
mysql -u root

4.mysqlデータベースの使用
use mysql;


このような情報が表示されます.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

5.パスワードの再設定
update user set password=PASSWORD("yournewpassword") where User='root';
yournewpasswordあなたが設定したパスワードに置き換えます
これらを見ることができます
mysql> update user set password=PASSWORD("yournewpassword") where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

6.権限の再設定
flush privileges;

以下におなじみのヒントがあれば、基本的に成功します.
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.終了
quit

8.MYSQLの再起動
UbuntuまたはDebianで
sudo /etc/init.d/mysql stop

そして
sudo /etc/init.d/mysql start

CentOS,Fedora,RHELで:
sudo /etc/init.d/mysqld stop

そして
sudo /etc/init.d/mysqld start

9.再ログイン
mysql -u root -p

設定したパスワードを入力します.DONE
Happy Hacking