如果忘记了登录密码
在/etc/my.cnf末尾 加入skip-grant-tables,保存,跳过身份验证。
vim /etc/my.cnf
然后重启mysql
登录mysql
mysql -u root -p
这个时候直接空格即可,无需输入密码
然后选择数据库
use mysql;
再修改密码
update mysql.user set password=password('123456') where user='root';
这个时候发现提示报错了
Unknown column 'password' in 'field list'
采用如下语句来更新,因为新版本mysql采用authentication_string替代了password字段
update mysql.user set authentication_string=password('root') where user='root';
成功。
最后记得去/etc/my.cnf里面把skip-grant-tables去掉