工作笔记 — Reset MySQL Root 密码

有时候一次过手上可能会做好几个Project。一时没注意很可能就会把某个Project的密码忘掉,而需要费事费力把它找回。

今天就遇到这问题了。。。我忘了MySQL的Root密码。。。
<img src="/plugins/HC_Emoticons/emoticons/red/red%2852%29.png" alt="狂汗" longdesc="” border=”0″>

还好谷歌大神中真的是什么都有,但为了以防万一,我还是自己做一份记录好了。现在的MySQL用户目录如果真的要找某些东西,很可能需要花费上一整天都未必能找到要的。。。

Step1:关闭MySQL服务
# /etc/init.d/mysql stop

Step2 : 利用 –skip-grant-tables指令,跳过密码验证。
# /usr/bin/mysqld-safe –skip-grant-tables

(注:mysqld-safe为启动MySQL服务器于独立运作模式。除了localhost,不接受外界登陆)

成功启动时会看到以下字眼:

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

Step3 : 通过指令符,用root进入MySQL。这次可以省略密码。
# mysql -u root

Step4 : 为root用户设定新密码
mysql> use mysql;
mysql> update user set password=PASSWORD(“新密码”) where User=”root”;
mysql> flush privileges;
mysql> quit

Step5 : 关闭MySQL-Safe服务
# /etc/init.d/mysql stop

Step6 : 重启MySQL服务
# /etc/init.d/mysql start

完成。

One Reply to “工作笔记 — Reset MySQL Root 密码”

  1. 唔?
    什么来的?
    好奇ING但是还是不明白。
    哎呀呀 抱歉啊~电脑白痴甘拜下风

Comments are closed.