当前位置:网站首页>Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
2022-07-31 05:07:00 【m0_67402125】
(1)如果是最后的提示是NO则说明当前数据的登录需要使用密码,而此次登录时并没有使用密码登录,只需进行密码登录。
(2)如果使用密码登录时,报错YES,则说明当前用户的密码字段或者Host字段出现问题,则可先通过绕过密码的方式进行登录查看登录用户信息。
绕过密码登录
(1)如果mysql的版本是5.7以下,则直接在/etc文件夹下找到my.cnf,然后在[mysqld]字段下添加一行skip-grant-tables,保存完重启数据库,然后就可以直接使用mysql免密登录数据库。
(2)如果mysql的版本是5.7以上,在/etc文件夹下是找不到my.cnf文件的,所以只需要新建一个my.cnf,然后添加两行代码
[mysqld]
skip-grant-tables
保存完重启数据库,然后就可以直接使用mysql免密登录数据库。
修改用户密码
(1)免密登录之后,use mysql切换数据库,然后依次执行
update user set authentication_string = PASSWORD('new password') where User = 'username';
FLUSH PRIVILEGES;
第一句sql指令如果数据库版本低于5.7时,user表中的密码字段应该是password,所以需要将指令修改为
update user set password = PASSWORD('new password') where User = 'username';
(2)修改之后可以通过sql指令查看当前用户信息
Select Host, authentication_string from user where User = ‘username’;
此处需要特别说明,该表中的Host字段指示的是当前登录数据用户的主机ip,比如说Host字段中是localhost,那如果想登录数据库,则只能是本机登录,所以在做开发时需要将数据库的地址设置为localhost,如果想要远程访问,可以将Host改为想要进行访问的主机的ip地址即可。(192.168.1.% 该表达式可以匹配所有子网为192.168.1.xxxx的所有ip)
所以如果Host不是localhost,就算密码修改成功之后,也无法在本机进行登录,所以再测试的时候还会报错ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
(3)修改完通过quit退出数据库,将my.cnf文件中新增的代码去掉,然后
service mysql restart
重启数据库,即可正常通过密码登录数据库。
一定一定一定要检查数据库用户的Host字段,因为它直接决定哪些主机可以通过当前数据库用户进行登录!!!!
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- wx.miniProgram.navigateTo在web-view中跳回小程序并传参
- Minesweeper game - C language
- Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
- 【ORACLE Explain 详解】
- .NET-6.WinForm2.NanUI学习和总结
- STM32HAL库修改Hal_Delay为us级延时
- Sql解析转换之JSqlParse完整介绍
- Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
猜你喜欢
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
Simple read operation of EasyExcel
SQL injection of DVWA
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
【C语言】操作符详解
Unity URP渲染管线摄像机核心机制剖析
[Cloud Native] DevOps (5): Integrating Harbor
MySQL transaction (transaction) (this is enough..)
Unity教程:URP渲染管线实战教程系列【1】
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
随机推荐
Workflow番外篇
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
[Detailed explanation of ORACLE Explain]
View source and switch mirrors in two ways: npm and nrm
.NET-6.WinForm2.NanUI learning and summary
1. Get data - requests.get()
Unity URP渲染管线摄像机核心机制剖析
Go语学习笔记 - 处理超时问题 - Context使用 | 从零开始Go语言
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
MySQL optimization slow log query
WPF WPF 】 【 the depth resolution of the template
sql statement - how to query data in another table based on the data in one table
参考代码系列_1.各种语言的Hello World
矩池云快速安装torch-sparse、torch-geometric等包
C Implementation of Simple Network File Copy
Centos7 install mysql5.7 steps (graphical version)
三道leetcode上的oj题
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
110 MySQL interview questions and answers (continuously updated)