Access denied for user 'root'@'localhost' (using password:YES)

版权所有,未经博主允许不得转载。

今天发现服务器mysql连接不上,报

can't connect to mysql server on 'root'@'ip' (61)

照例ssh到服务器,发现mysql也进入不了,报错Access denied for user 'root'@'localhost' (using password:YES), 以前都是可以的(好几次出现这种情况)。今天整理下--系统linux. mysql 5.5

谷歌了下,发现解决方法:

1、首先查看mysql 3306端口是否打开。。命令

netstat -an | grep 3306

这个时候发现3306监听的确没有开启。so这个时候停掉mysql服务。命令

/etc/init.d/mysql stop

查看mysql是否停掉,命令

ps -ax |grep mysql

若停掉,则不会看到mysql进程

若未停掉,多试几次

2、then启动mysql,mysqld_safe方式进入mysql  命令

mysqld_safe --user=mysql &

#mysql -u root

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql>FLUSH PRIVILEGES;

重启mysql

#/etc/init.d/mysql restart

#mysql -u root -p

Enter password:

mysql远程登录授权grant命令

命令:

grant all privileges on *.* to 'USER'@'IP' identified by 'PASS' 

USER:登录用户名

PASS:密码

IP:ip地址或主机号

*.*:数据库.数据表名 

all privileges:所有权限 也可为select,insert ,update,delete

整理下,以被以后遇到又浪费太多时间。

原文地址:https://www.cnblogs.com/symen/p/5715273.html