mysql忘记root密码,如何重新设置密码?
时间 2020-12-28
标签
mysql
重置密码
问题描述:
忘记mysql的root密码情况下,修改密码update user set password=password('123456') where user='root' ;
出现错误:Unknown column 'password' in 'field list'
。查看mysql.user表发现表中没有password
字段,取而代之的是authentication_string
字段。
重置密码
1. vim /etc/my.cnf 在最后加入skip-grant-tables
2. 重启mysql service mysqld restart
3. 输入 mysql 直接登录MySQL数据库,然后use mysql
4.更新密码:update user set authentication_string=password(‘123456’) where user=’root’;
5.编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL,service mysqld restart,否则MySQL仍能免密码登录
6.mysql -u root -p 输入密码即可登录mysql