系统:CentOS 7.9 64位
登录MySQL时出现:
Error: Access denied for user ‘root’@‘localhost’ (using password: YES)
解决:
[root@iZbp1av5n9d40dgk6av4cbZ ~]# /etc/init.d/mysqld stop
[root@iZbp1av5n9d40dgk6av4cbZ ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@iZbp1av5n9d40dgk6av4cbZ ~]# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
在更新user表时提示:
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
解决:
因为密码存放在authentication_string中,所以要先把列名改成password,或者直接使用authentication_string字段名。
alert table user change authentication_string password varchar(100);