止mysql数据库
/etc/init.d/mysqld stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
修改密码是报错
ERROR 1054 (42S22): Unknown column ‘password’ in 'field list’
因为mysql-5.7及以上版本已没有password字段,已将password字段修改为authentication_string字段
解决方法:
将password修改为authentication_string
update user set authentication_string=password('you new password') where user='root';
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: <输入新设的密码newpassword>
本文档详细介绍了在MySQL 5.7及以上版本中,由于`password`字段被替换为`authentication_string`,如何正确地更改root用户的密码。步骤包括停止MySQL服务,启动带有特定选项的mysqld_safe,用root用户登录,更新`authentication_string`字段,刷新权限,重启MySQL服务,最后使用新密码登录验证。
2191

被折叠的 条评论
为什么被折叠?



