文章详情

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

请输入下面的图形验证码

提交验证

短信预约提醒成功

Mysql连接错误ERROR 1045 (28000): Access denied for user问题的解决方法

2024-04-02 19:55

关注

本篇内容主要讲解“Mysql连接错误ERROR 1045 (28000): Access denied for user问题的解决方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Mysql连接错误ERROR 1045 (28000): Access denied for user问题的解决方法”吧!

  1. 从192.168.111.99上连接远程数据的时候报错:


  2. [mysql@LVS01 mysql_5621]$ mysql -uroot -p123 -h292.168.111.10 -P 5621

  3. Warning: Using a password on the command line interface can be insecure.

  4. ERROR 1045 (28000): Access denied for user 'root'@'192.168.111.99' (using password: YES



  5. 查看远程主机权限:


  6. mysql> use mysql;

  7. Database changed

  8. mysql> select user,host,password from user;

  9. +-------+----------------+-------------------------------------------+

  10. | user | host | password |

  11. +-------+----------------+-------------------------------------------+

  12. | root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  13. | root | mysql-svr1 | |

  14. | root | 127.0.0.1 | |

  15. | root | ::1 | |

  16. | repl | 192.168.110.20 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  17. | repl | 192.168.111.20 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  18. | repl | 192.168.111.30 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  19. | repl | 192.168.111.10 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  20. | user1 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  21. | root | 192.168.111.20 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  22. | root | 192.168.111.30 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  23. | root | 192.168.111.10 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  24. | admin | 192.168.111.10 | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |

  25. | root | 192.168.111.% | |

  26. | root | 192.168.111.99 | |

  27. | root | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  28. +-------+----------------+-------------------------------------------+

  29. 16 rows in set (0.00 sec)


  30. 发现已经给192.168.111.99授权了,可为什么还是连不上?


  31. 和192.168.111.99相关的权限是下面几行:



  32. | root | 192.168.111.% | |

  33. | root | 192.168.111.99 | |

  34. | root | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |


  35. 尝试使用空密码登陆成功:


  36. [mysql@LVS01 mysql_5621]$ mysql -uroot -h292.168.111.10 -P 5621

  37. Welcome to the MySQL monitor. Commands end with ; or \g.

  38. Your MySQL connection id is 20216

  39. Server version: 5.6.21-log Source distribution

  40. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

  41. Oracle is a registered trademark of Oracle Corporation and/or its

  42. affiliates. Other names may be trademarks of their respective

  43. owners.

  44. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  45. mysql>


  46. 删除密码为空的用户:


  47. mysql> drop user root@'192.168.111.%';

  48. Query OK, 0 rows affected (0.31 sec)

  49. mysql> drop user root@'192.168.111.99';

  50. Query OK, 0 rows affected (0.00 sec)


  51. mysql> select user,host,password from user;


  52. +-------+----------------+-------------------------------------------+

  53. | user | host | password |

  54. +-------+----------------+-------------------------------------------+

  55. | root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  56. | root | mysql-svr1 | |

  57. | root | 127.0.0.1 | |

  58. | root | ::1 | |

  59. | repl | 192.168.110.20 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  60. | repl | 192.168.111.20 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  61. | repl | 192.168.111.30 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  62. | repl | 192.168.111.10 | *A424E797037BF97C19A2E88CF7891C5C2038C039 |

  63. | user1 | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  64. | root | 192.168.111.20 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  65. | root | 192.168.111.30 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  66. | root | 192.168.111.10 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  67. | admin | 192.168.111.10 | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |

  68. | root | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

  69. +-------+----------------+-------------------------------------------+

  70. 14 rows in set (0.00 sec)

  71. mysql>


  72. 再次使用密码登陆成功:


  73. [mysql@LVS01 mysql_5621]$ mysql -uroot -p123 -h292.168.111.10 -P 5621

  74. Warning: Using a password on the command line interface can be insecure.

  75. Welcome to the MySQL monitor. Commands end with ; or \g.

  76. Your MySQL connection id is 20312

  77. Server version: 5.6.21-log Source distribution

  78. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

  79. Oracle is a registered trademark of Oracle Corporation and/or its

  80. affiliates. Other names may be trademarks of their respective

  81. owners.

  82. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  83. mysql>


  84. 总结:

  85. 出现这个错误的原因是同一个用户有不同主机范围的权限时,按最匹配的一个主机验证权限。

  86. 也就是说从192.168.111.99登陆服务器时,验证顺序为:

  87. root@'192.168.111.99'

  88. root@'192.168.111.%'

  89. root@'%'


  90. 参考文档:

  91. http://dev.mysql.com/doc/refman/5.7/en/connection-access.html

  92. When multiple matches are possible, the server must determine which of them to use. It resolves this issue as follows:


  93. Whenever the server reads the user table into memory, it sorts the rows.


  94. When a client attempts to connect, the server looks through the rows in sorted order.


  95. The server uses the first row that matches the client host name and user name.


  96. The server uses sorting rules that order rows with the most-specific Host values first. Literal host names and IP addresses are the most specific. (The specificity of a literal IP address is not affected by whether it has a netmask, so 192.168.1.13 and 192.168.1.0/255.255.255.0 are considered equally specific.) The pattern '%' means “any host” and is least specific. The empty string '' also means “any host” but sorts after '%'. Rows with the same Host value are ordered with the most-specific User values first (a blank User value means “any user” and is least specific). For rows with equally-specific Host and User values, the order is indeterminate.


  97. 建议:

  98. (1)用户授权时,按最小主机范围授权,并且赋予密码,只授权一次。

  99. (2)如果将来主机范围变化,重新授权时可删除旧授权,否则可能因为两次授权密码不同导致类似问题。

到此,相信大家对“Mysql连接错误ERROR 1045 (28000): Access denied for user问题的解决方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

阅读原文内容投诉

免责声明:

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

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

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     801人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     348人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     311人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     432人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     220人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯