解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

自己花了120大洋买的腾讯云centOs服务器一年,学生版的。
服务器经常出现这种问题,进入mysql时候,密码也对,就是一直提示我错误 ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)我也没搞懂为啥会出现,希望有知道的大佬告知一下,反正就是找办法先解决,就是修改密码。
解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决方案:重置密码

  • 在命令行输入vim /etc/my.cnf,

    [mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程
    解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • 按键盘ESC 然后输入 :wq!保存并退出
    解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • 在控制台输入service mysqld restart 重启MySQL服务
    解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • 免密码登陆,控制台输入 mysql -u root -p 回车,然后不用输入密码,直接再按回车,即可进入mysql
    解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • 修改密码在数据库命令行里输入set password for [email protected] = password(‘123456’);这里我密码是123456,注意语句结束后的“;”

  • 然后输入quit;或者按control+c键,退出mysql命令行

  • 再次输入vim /etc/my.cnf,把 [mysqld]后面的“skip-grant-tables”删除,然后按键盘ESC 输入 :wq!保存并退出
    解决Linux(服务器)错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • 最后在控制台输入service mysqld restart 重启MySQL服务,这样我们就能通过密码123456进入mysql了

  • 可以加我vx:sun632928843 一起学习加油