Linux连接mysql报错:Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法以及忘记密码

最近在腾讯云上买了一服务器玩想,然后为服务配置好mysql

mysql -uroot -pxxx

要进入发现报错

Linux连接mysql报错:Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法

因为第一次遇到这个问题,上网百度了半天,都是一个答案

1.停止mysqld服务
service mysqld stop


进入mysql-bin目录
./mysqld_safe --skip-grant-tables   在安全模式下执行,并且跳过权限


然后mysql -u root  直接进入


切换数据库 use mysql

update user set password=PASSWORD("你的密码") where User = 'root';


这个方法确实能进来数据库,但是重新登录的话还是会提示Access的错误信息,应在mysql的配置文件中加一条skip-grant-tables 这样就达到了效果, 上面的方法应该是忘记密码 应该怎么修改的.

猜你喜欢

转载自blog.csdn.net/bwddd/article/details/80508300