也许有些朋友和我一样这么粗心,把mysql的root管理密码丢失了,下面是我查资料后找回root密码的办法:
杀掉进程
# killall -TERM mysqld
启动(不用密码)
# /usr/bin/mysqld_safe --skip-grant-tables &
(这一步浪费了我很长时间,因为早期版本这个模块不是mysqld_safe而是safe_mysqld,所以用网上其他人的经验一直说找不到文件)
登录mysql
msql> mysql -u root
更新密码
mysql> update mysql.user set password=password("新密码") where user="root";
刷新权限
mysql>flush privileges;
退出
mysql>exit;
重新登录以后看看吧,
# /etc/rc.d/init.d/mysqld start
# mysql -u root -p
需要注意的是更新之前,可以看看密码是不是改变了
mysql>select user,host,password from mysql.user;
/rc.d/init.d/mysqld start
正常登录
mysql -u root
最后建议大家设置一个admin的超级管理员
mysql> grant all privilages on *.* to admin@localhost identified by '********' with grant option;
mysql> grant all privilages on *.* to admin@"%" identified by "********" with grant option;
建立新用户设置新密码
set password for root@'buputong.com'=password('***********');