我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Mysql Access denied for user ‘root‘@ ‘*.*.*.*‘ (using password: YES)异常处理

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Mysql Access denied for user ‘root‘@ ‘*.*.*.*‘ (using password: YES)异常处理

一、异常错误

PS C:\Users\10568> mysql -u root -pEnter password: ****ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Access denied表示拒绝访问,using password:NO/YES是否输入了密码。

在这里插入图片描述

二、原因

其中一种原因是mysql自启动的bug,mysql的3306端口号被自己占用,需要关闭mysql服务,再重新启动,我目前这样做可以解决,当然,也可能是因为MySQL服务器上不存在的用户尝试访问数据库。可以参考stack overflow的问题去解决。

stack overflow的回答是在默认情况下,根MySQL用户设置为使用auth_socket插件进行身份验证,而不是使用密码进行身份验证。在许多情况下,这允许更高的安全性和可用性,但是当您需要允许外部程序(例如,phpMyAdmin)访问用户时,它也会使事情复杂化。为了使用密码以root身份连接到MySQL,您需要将其身份验证方法从auth_socket切换到mysql_native_password。
参考:Access Denied for User ‘root’@‘localhost’ (using password: YES) -No Privileges?:https://stackoverflow.com/questions/17975120/access-denied-for-user-rootlocalhost-using-password-yes-no-privileges

三、解决方法

查看3306端口情况,发现PID进程为5296

netstat -ano|findstr 3306

在这里插入图片描述

使用命令taskkill /PID 5964 -t -f将进程杀死,或者直接在任务管理器中结束任务

之后重新启动mysql

net start mysql

在这里插入图片描述

重新进入mysql即可

在这里插入图片描述

如果是Ubuntu系统可以参考以下回答:

MySQL Error: : 'Access denied for user ‘root’@‘localhost’:https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost
In Ubuntu systems running MySQL 5.7 (and later versions), the root
MySQL user is set to authenticate using the auth_socket plugin by
default rather than with a password. This allows for some greater
security and usability in many cases, but it can also complicate
things when you need to allow an external program (e.g., phpMyAdmin)
to access the user.

In order to use a password to connect to MySQL as root, you will need
to switch its authentication method from auth_socket to
mysql_native_password. To do this, open up the MySQL prompt from your
terminal:

sudo mysql

Next, check which authentication method each of your MySQL user
accounts use with the following command:

SELECT user,authentication_string,plugin,host FROM mysql.user;

Output

±-----------------±------------------------------------------±----------------------±----------+ | user | authentication_string |
plugin | host |
±-----------------±------------------------------------------±----------------------±----------+ | root | |
auth_socket | localhost | | mysql.session |
*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys |
*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint |
*CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
±-----------------±------------------------------------------±----------------------±----------+ 4 rows in set (0.00 sec) In this example, you can see that the root
user does in fact authenticate using the auth_socket plugin. To
configure the root account to authenticate with a password, run the
following ALTER USER command. Be sure to change password to a strong
password of your choosing, and note that this command will change the
root password you set in Step 2:

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY
‘password’;

Then, run FLUSH PRIVILEGES which tells the server to reload the grant
tables and put your new changes into effect:

FLUSH PRIVILEGES;

Check the authentication methods employed by each of your users again
to confirm that root no longer authenticates using the auth_socket
plugin:

SELECT user,authentication_string,plugin,host FROM mysql.user;

Output

±-----------------±------------------------------------------±----------------------±----------+ | user | authentication_string |
plugin | host |
±-----------------±------------------------------------------±----------------------±----------+ | root | *3636DACC8616D997782ADD0839F92C1571D6D78F |
mysql_native_password | localhost | | mysql.session |
*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys |
*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint |
*CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost |
±-----------------±------------------------------------------±----------------------±----------+ 4 rows in set (0.00 sec) You can see in this example output that the
root MySQL user now authenticates using a password. Once you confirm
this on your own server, you can exit the MySQL shell:

exit

来源地址:https://blog.csdn.net/qq_46207024/article/details/131177552

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Mysql Access denied for user ‘root‘@ ‘*.*.*.*‘ (using password: YES)异常处理

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

Mysql Access denied for user ‘root‘@ ‘*.*.*.*‘ (using password: YES)异常处理

目录 一、异常错误二、原因三、解决方法 一、异常错误 PS C:\Users\10568> mysql -u root -pEnter password: ****ERROR 1045 (28000): Access denie
2023-08-23

mysql ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: YES)

遇到这个问题搞了很久,自己记下来。方法是百度的,亲测有效。 ERROR 1045 (28000): Access denied for user ‘ODBC’@‘localhost’ (using password: NO) ERROR 1
2023-08-16

Mysql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES/NO)个人解决方法 分享一下

前言 Mysql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES/NO) 看了很多篇文章都没解决, 下面是我个人解决方法 分享一下 一、个人配置:系统w
2023-08-16

Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解决

这篇文章主要介绍“Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)如何解决”,在日常操作中,相信很多人在Mysql
2023-06-30

编程热搜

目录