解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

最近遇到一个问题,就是后台连不上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的服务,如图

file

这时候在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连接就可以了。

file

方法二:

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

file

备份这些文件后,卸载原来的数据库程序并删除文件夹和注册表,重装数据库后关闭数据库服务,把备份的文件放入对应的位置,有重名的点击替换,然后再重启数据库服务。这个时候打开数据库,你就会发现原来的数据库已经都出现了,完全一模一样!

### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 70 面 0 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2: 使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,并分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值