当前位置:网站首页>解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
2022-07-03 13:22:00 【程序猿DaBo】
最近遇到一个问题,就是后台连不上mysql数据库,用navicat打开数据库提示1045 Access denied for user 'root'@'localhost' (using password: YES)。这个问题在网上有一个解决办法,但是全网都是复制了一个人的,并且没有给出到底是什么原因导致的这个问题。今天我针对这个问题给出原因解释和两个解决此问题的方法!

原因:
1.数据库密码被篡改了!
没错,就是这个原因。但是很多人会立马反驳,我自己的电脑一直用着好好的,怎么会被篡改了呢?黑客的手段厉害着呢,篡改你的数据库密码不是主要目的,目的是篡改后进入你的数据库备份数据库文件然后删除本地数据库,要挟你索要比特币才是主要目的。
2.数据库权限变更了!
这个原因与你机器的账户权限变更有很大的关系,实际发生场景有很多,就不举例了。
下面就给出两个解决办法,根据个人喜好随便一个都可以
方法一:
编辑mysql配置文件my.ini(在mysql的安装目录下,不同电脑可能不一样,参考目录①D:\Program Files\MySQL\MySQL Server 5.0\my.ini;②C:\ProgramData\MySQL\MySQL Server 8.0\my.ini;),在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql
1.打开cmd,点击“开始”->“运行”(快捷键Win+R)。
2.停止:输入 net stop mysql
3.启动:输入 net start mysql
也可以在计算机-管理-服务里面找到MySQL的服务,如图

这时候在cmd里面输入mysql -u root -p就可以不用密码登录了,出现 password:的时候直接回车可以进入,不会出现ERROR 1045 (28000),但很多操作都会受限制,因为没有grant权限。
继续按下面的流程走:
1.进入mysql数据库:
mysql> use mysql;
Database changed
2.给root用户设置新密码:
mysql> update user set password=password("新密码") where user="root";
Query OK, 1 rows affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
3.刷新数据库
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4.退出mysql:
mysql> quit;
Bye
改好之后,再修改一下my.ini这个文件,把我们刚才加入的 "skip-grant-tables"这行删除,保存退出再重启mysql服务,再重新用Navicat连接就可以了。

方法二:
卸载原有的数据库,包括主程序、注册表和C盘文件夹,但是一定要注意备份C盘C:\ProgramData\MySQL\MySQL Server (你卸载的数据库版本)\data下面的数据库文件,这是你之前数据库表文件等,要恢复数据库必须备份下来,后面才可以恢复数据。此外,此文件夹是默认隐藏的。
复制data文件夹下面你之前创建的数据库,名字都是对应的,你有印象就能知道哪个是你创建的数据库,还有三个文件也是必须备份的,看图:

备份这些文件后,卸载原来的数据库程序并删除文件夹和注册表,重装数据库后关闭数据库服务,把备份的文件放入对应的位置,有重名的点击替换,然后再重启数据库服务。这个时候打开数据库,你就会发现原来的数据库已经都出现了,完全一模一样!
边栏推荐
- Record 405 questions about bank callback post request
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Asp. Net core1.1 without project JSON, so as to generate cross platform packages
- 8 Queen question
- JS 将伪数组转换成数组
- untiy世界边缘的物体阴影闪动,靠近远点的物体阴影正常
- 记录关于银行回调post请求405 问题
- Go 1.16.4: manage third-party libraries with Mod
- Spark实战1:单节点本地模式搭建Spark运行环境
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
猜你喜欢

如何使用lxml判断网站公告是否更新

CVPR 2022 | 美团技术团队精选6篇优秀论文解读

Unity embeddedbrowser browser plug-in event communication

Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)

Mycms we media mall v3.4.1 release, user manual update

Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases

Go language unit test 3: go language uses gocovey library to do unit test
![[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]](/img/95/09552d33d2a834af4d304129714775.png)
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]

SQL Injection (GET/Search)

MySQL 数据处理值增删改
随机推荐
TensorBoard可视化处理案例简析
Field problems in MySQL
Flutter动态化 | Fair 2.5.0 新版本特性
Mastering the cypress command line options is the basis for truly mastering cypress
Unity Render Streaming通过Js与Unity自定义通讯
JSON serialization case summary
Record 405 questions about bank callback post request
JVM系列——概述,程序计数器day1-1
logback日志的整理
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
Go language web development series 30: gin: grouping by version for routing
Golang — template
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
太阳底下无新事,元宇宙能否更上层楼?
Error running 'application' in idea running: the solution of command line is too long
Screenshot of the operation steps of upload labs level 4-level 9
pytorch 载入历史模型时更换gpu卡号,map_location设置
实现CNN图像的识别和训练通过tensorflow框架对cifar10数据集等方法的处理
There is nothing new under the sun. Can the meta universe go higher?
Red hat satellite 6: better management of servers and clouds