mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)

当我第一次安装完mysql登录时,明明输入的正确密码,但却提示错误:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password:yes),下面就是我的解决方法,希望对小伙伴们有帮助。
第一步:打开windows命令行模式

第二步:输入命令: net stop 服务器名(我这里是mysql5.5)关闭mysql服务
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
第三步:输入命令
mysqld --defaults-file=“D:\softwareinstall\Mysqlinstall\MySQL Server 5.5\my.ini” --console --skip-grant-tables
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
需要注意的是,D:\softwareinstall\Mysqlinstall\MySQL Server 5.5\my.ini是my.ini文件的路径名,在mysql的安装路径下,如果不知道可以搜索my.ini这个文件
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
第四步:另外启动一个命令行窗口,输入命令: mysql -uroot -p 回车然后输入之前无法登录那个正确的密码
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
第五步:输入命令: use mysql;
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
第六步:(5.7.11以前)输入命令update user set password=password(“123456”) where user=“root”;
(5.7.1或者以后)输入update user set authentication_string=password(“123456”) where user=“root”;
mysql输入正确密码无法登陆,出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password:yes)
到这里就结束了,以后的登陆密码就是123456