mysql登录报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

  • https://blog.csdn.net/m0_70556273/article/details/126490767

在MySQL登录时出现Access denied for user ‘root’@‘localhost’ (using password: YES) 拒绝访问

img

对于出现拒绝访问root用户的解决方案
错误1045(28000):用户’root’@‘localhost’(使用密码:YES)拒绝访问

首先解析此英文:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES);
解析的地方有两处:1.Access denied(拒绝访问);2.using password:NO/YES

一、出现access denied的原因有如下可能:

1)mysql的服务器停止:
  若MySQL已经没有启动,重启MySQL服务器:systemctl restart mysqld
2)用户的端口号或者IP导致:
  若用户的端口号与IP(3306/3307)不一致,打开my.ini文件进行编辑。全部编辑替换为: port=X
3)mysql的配置文件错误----my.ini等文件:
  my.ini文件误输入无效内容,不知道到何处。复制替换该文件;有人已经对my.ini文件进行解释以及注释:https://blog.csdn.net/lienfeng6/article/details/78140404
4)root用户的密码错误(后面解决)

二、出现 using password的原因如下:

不输入密码:

img

错误的密码:

img

登录时跳过权限检查

解决方案:

vim /etc/my.cnf文件;
在[mysqld]后添加skip-grant-tables(登录时跳过权限检查)

skip-grant-tables

img

重启MySQL服务:sudo systemctl restart mysqld

img

修改密码

img

img

登录mysql,输入mysql –uroot –p;直接回车(Enter)

img

修改密码和远程授权

输入:

set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);

如果报:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

img

输入:flush privileges;

img

再次输入:set password for ‘root’@‘localhost’=password(‘Admin123@qwe’);

img

为避免麻烦,再次设置远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'Admin123@qwe' WITH GRANT OPTION;

flush privileges;
privileges
英
/ˈprɪvəlɪdʒɪz/
n.
特权,特殊待遇(privilege 的复数)

privilege
n.
特权,特殊待遇;荣幸,光荣;(富人或上层阶级的)权势;(律师、医生及其他专业人士的)保密权;言行免责权(尤指议员的权利);<>(授予个人,公司,某地的)特许经营权;(生活)优越
v.
<正式> 给予特权,特别优待;特免,免除(某人)
    
    
    

grant
v.
授予,给予;承认
n.
补助金,拨款;(政府给予的)土地;<正式>给予,授予;合法转让
    
    
    
    
identified
英
/aɪˈdentɪfaɪd/

adj.
被识别的;经鉴定的;被认同的
v.
鉴定;辨认(identify 的过去式和过去分词)
    
identify
英
/aɪˈdentɪfaɪ/
v.
认出,识别;查明,确认;发现;证明(身份),表明;认同,理解;认为……和……一致;和(某人)打成一片

img

退出:exit

img

再把my.ini的skip-grant-tables删除或者注释掉

img

重启MySQL:sudo systemctl restart mysqld

img

再次连接,成功

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐