1、结束当前正在运行的mysql进程。
service mysql stop
2、用mysql安全模式运行并跳过权限验证。
/www/server/mysql/bin/mysqld_safe --skip-grant-tables &
3、重开一个终端窗口以root身份登录mysql,
输入:mysql -u root -p 命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中
4、修改密码
mysql> update user set password=password('password') where user='root';
如果出现以下错误:
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
原因是mysql数据库下已经没有password这个字段了,password字段改成了authentication_string即可
update user set authentication_string=PASSWORD('password') where Use
r='root';
5、重新加载系统权限表
mysql> flush privileges;
6、关闭安全模式运行(关闭刚才安全模式运行的终端窗口)
service mysql stop
7、启动数据库
service mysql start