当前位置:网站首页>解决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文件夹下面你之前创建的数据库,名字都是对应的,你有印象就能知道哪个是你创建的数据库,还有三个文件也是必须备份的,看图:
备份这些文件后,卸载原来的数据库程序并删除文件夹和注册表,重装数据库后关闭数据库服务,把备份的文件放入对应的位置,有重名的点击替换,然后再重启数据库服务。这个时候打开数据库,你就会发现原来的数据库已经都出现了,完全一模一样!
边栏推荐
- RichView TRVStyle ListStyle 列表样式(项目符号编号)
- 掌握Cypress命令行选项,是真正掌握Cypress的基础
- 静态链表(数组的下标代替指针)
- IBEM mathematical formula detection data set
- Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe for the online account manager to open an account
- MySQL installation, uninstallation, initial password setting and general commands of Linux
- 挡不住了,国产芯片再度突进,部分环节已进到4nm
- php 迷宫游戏
- Go language web development series 27: Gin framework: using gin swagger to implement interface documents
- Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
猜你喜欢
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
MySQL installation, uninstallation, initial password setting and general commands of Linux
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
Go language unit test 3: go language uses gocovey library to do unit test
Flutter dynamic | fair 2.5.0 new version features
Flutter dynamic | fair 2.5.0 new version features
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
随机推荐
Spark实战1:单节点本地模式搭建Spark运行环境
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected
SQL Injection (POST/Select)
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
Leetcode-1175. Prime Arrangements
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
挡不住了,国产芯片再度突进,部分环节已进到4nm
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
[technology development-24]: characteristics of existing IOT communication technology
Kivy教程之 如何自动载入kv文件
Go language unit test 3: go language uses gocovey library to do unit test
pytorch 载入历史模型时更换gpu卡号,map_location设置
Mastering the cypress command line options is the basis for truly mastering cypress
Libuv Library - Design Overview (Chinese version)
User and group command exercises
MapReduce实现矩阵乘法–实现代码
Mycms we media mall v3.4.1 release, user manual update
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
Heap structure and heap sort heapify