Linux中MYSQL5.7出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

一 关于出现”ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)“错误的解决:

1 查看版本和修改配置

mysql -V								//查看对应的版本号,一般我们的服务器版本为mysql5.7.30
whereis my.cnf							//查找mysql对应的配置文件,路径一般为/etc/my.cnf,mysql8.0以上在/etc/mysql/conf.d/mysql.cnf
vim /etc/my.cnf

在[mysqld]中添加以下内容:
skip-grant-tables

2 重启服务

service mysqld restart	

3 修改密码

mysql -uroot -p								//输入后直接按enter即可,无需输入密码
use mysql
select * from user;							//查看是否有authentication_string字段
update user set authentication_string=password("你的新密码") where user='root';	//若数据库是5.7及以上的用该命令.因为5.7之前没有authentication_string字段,5.7之前的字段叫password
//update user set password=password("你的新密码") where user="root";		//5.7之前的版本用这个命令
flush privileges;	

4 修改登录主机

//update user set host = '%' where user = 'root';				//修改mysql只能在本地登录而无法远程登录(建议用下面的)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你刚刚改的密码';		//这里面*.*代表是所有库.所有表, root是用户名, %代表所有ip都可访问,也可指定ip访问,例如'root'@'172.17.5.90',123456代表root用户的密码;
flush privileges;
select host,user from user;										//查看host可以看到localhsot已经变成%。
quit;

5 修改回配置

vim /etc/my.cnf
然后去掉刚刚添加的skip-grant-tables。

6 重启服务

service mysqld restart
再次登录即可成功
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个报错是由于MySQL登录时使用的用户名和密码不正确导致的。可以尝试按照以下步骤解决该问题: 1. 检查你输入的用户名和密码是否正确。确保没有输入错误的字符或者大小写错误。 2. 检查MySQL服务是否正在运行。如果没有运行,请启动MySQL服务。 3. 如果确定用户名和密码是正确的,但仍然无法登录,可以尝试重置root用户的密码。首先关闭正在运行的MySQL服务。 4. 打开cmd窗口,转到MySQL的bin目录。 5. 输入`mysqld --skip-grant-tables`并按回车键。这将启动MySQL服务时跳过权限表认证。 6. 在另一个cmd窗口再次转到MySQL的bin目录。 7. 输入`mysql`并按回车键,如果成功,会出现MySQL提示符">"。 8. 连接到权限数据库:`use mysql;` 9. 修改密码:`update user set authentication_string=password('your new password') where user='root';`(别忘了最后加分号) 10. 刷新权限(必须步骤):`flush privileges;` 11. 退出:`quit;` 12. 重新启动MySQL服务,并使用用户名root和刚刚设置的新密码登录。 这样应该可以解决报错"Error 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)"的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ERROR 1045: Access denied for user root@localhost (using password: YES)的解决办法](https://blog.csdn.net/Caijingxiang/article/details/102534947)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [mysql5.7版本1045 报错 Access denied for user root@localhost (using password: YES)](https://blog.csdn.net/weixin_48504959/article/details/123745664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值