使用mysql -uroot -p 登陆MySQL时报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES);
解决方法
①配置免密登录
修改my.conf配置文件
vim /etc/my.conf
在任意位置添加如下参数
skip-grant-tables #配置免密码登录
②保存退出后重启mysql
systemctl restart mysql;
③重新登陆MySQL
直接在窗口出入mysql后回车即可登录了
mysql -u root -p #直接回车即可登录
④修改root密码
alter user 'root'@'%'identified by 'root@123';#修改密码为‘root@123’
-- 5.7及以后版本用:
update user set authentication_string=password('123') where user='root';
-- 5.7以前版本用:
update user set password=password('123') where user='root';
⑤退出MySQL 删除免密登陆参数
将my.conf文件里skip-grant-tables 参数注释或者删掉
保存文件后,重启MySQL
再登录即可