[MySQL] root密碼重設

如果忘記root密碼可以這樣重設

停止服務

1
# sudo /usr/local/etc/rc.d/mysql-server stop

以安全模式啟動mysql,並跳過檢查

1
# sudo mysqld_safe --skip-grant-tables

這時候登入不需要密碼

1
# mysql -u root

接著修改DB記錄,把root密碼設成123456,並重新載入權限

1
2
3
4
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD("123456") WHERE User='root';
mysql> flush privileges;
mysql> exit

最後重新啟動MySQL,大功告成

1
# sudo /usr/local/etc/rc.d/mysql-server restart
comments powered by Disqus