1045 access denied for user 'root'@'localhost' using password yes的解决方法

时间:2023-03-09 03:06:10
1045 access denied for user 'root'@'localhost' using password yes的解决方法

  今天把一个项目和项目的数据库都下载到了本地,安装好项目和在本地配置好数据库后,在浏览器登陆项目的后台却出现了以下错误:

   1045 access denied for user 'root'@'localhost' using password yes的解决方法

   后来上百度搜索了好几个答案,都是讲述修改数据库密码的步骤,但是就是没有说明为什么要修改密码,修改密码为‘123456’后,打开数据库却给我弹出以下错误:

   1045 access denied for user 'root'@'localhost' using password yes的解决方法

出现以上这个‘1045 - Access denied for user 'root'@'localhost'(using password NO)’错误是因为修改数据库密码为‘123456’后,连接数据库的时候没有把新密码‘123456’填上,后来填上后即可连接!

  之所以出现第一个错误:‘1045 - Access denied for user 'root'@'localhost'(using password YES)’的原因是我下载到本地的那个项目的数据库配置文件中数据库密码是‘123456’,而我当时本地数据库密码为空;

  综上所述,数据库配置信息必须要与其所相连接的数据库配置信息一致!

  

修改数据库密码步骤如下:

1:进入cmd,停止mysql服务:

  Net stop mysql
    到mysql的安装路径启动mysql,在bin目录下使用mysqld-nt.exe启动,

2:执行:mysqld-nt --skip-grant-tables(窗口会一直停止)

3:然后另外打开一个命入令行窗口,执行mysql(或者直接进Mysql Command Line Cilent),此时无需输入密码即可进入。

>use mysql

>update user set password=password("新密码") where user="root";

>flush privileges;

>exit

4:使用任务管理器,找到mysqld-nt的进程,结束进程!

在重新启动mysql-nt服务,就可以用新密码登录了

附:修改数据库密码的另外一种方式:

update mysql.user set password=PASSWORD('mysql56') where user='root';