使用mysql -uroot -p,然后输入密码登录mysql时,出现了如下错误:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
一般这个错误是由密码错误引起,解决的办法就是重置密码
解决步骤如下:
1.停止mysql数据库
执行命令:systemctl stop mysqld
2.用以下命令启动MySQL,以不检查权限的方式启动
执行命令:mysqld --user=root --skip-grant-tables &
3.登录mysql:mysql -uroot或mysql
4.更新root密码
mysql5.7以下版本:update mysql.user set password=password(‘你的密码’) where user=‘root’;
mysql5.7版本:update mysql.user set authentication_string=password(‘你的密码’) where user=‘root’;
5.刷新权限
执行命令:flush privileges;
6.退出mysql
输入:exit或quit
7.使用root用户重新登录mysql
mysql -uroot -p 回车
password:新密码
仅以此记录over