mysql''符号_MySQL'root'@'localhost'无法登录的解决办法_Mysql_七九推...

今天早上同事说mysql root账号登录不上了。我试了一下

#mysql -u root -p

提示”access denied for user ‘root’@’localhost’ (using password: yes)”

因为年后有同事离职,我第一反应是谁修改了root密码?按照忘记root密码来重置一下密码:

#/etc/init.d/mysql stop

#mysqld_safe –skip-grant-tables &

#mysql -uroot -p

mysql>update mysql.user set password=password(‘mypassword’) where user=’root’;

mysql>flush privileges;

mysql>quit

用新密码还是无法登录,提示跟上面一样。换一个非root账号登录,查看一下user表:

mysql> select user,host from user;

+———–+———+

| user | host |

+———–+———+

| root | 127.0.0.1 |

| night | % |

+———–+———+

怀疑默认的localhost没有映射到127.0.0.1?试试#mysql -u root -p xxxx -h 127.0.0.1,果然可以登录。

之前配置的同学没有给’root’@’localhost’和’root’@’ip’授权。

grant all privileges on . to ‘root’@’localhost’ identified by ‘mypassword’ with grant option;

grant all privileges on . to ‘root’@’118.192.91.xxx’ identified by ‘mypassword’ with grant option;

再查询一下用户表:

然后#mysql -u root -p xxxx,登录成功!

查了一下mysql -h localhost和mysql -h 127.0.0.1的区别,通过localhost连接到mysql是使用unix socket,而通过127.0.0.1连接到mysql是使用tcp/ip。看看状态:

mysql -h localhost > status

connection id: 639

current database: mysql

current user: root@localhost

ssl: not in use

current pager: stdout

using outfile: ”

using delimiter: ;

server version: 5.6.15-log source distribution

protocol version: 10

connection: localhost via unix socket

mysql -h 127.0.0.1 > status

connection id: 640

current database: mysql

current user: root@localhost

ssl: not in use

current pager: stdout

using outfile: ”

using delimiter: ;

server version: 5.6.15-log source distribution

protocol version: 10

connection: 127.0.0.1 via tcp/ip

希望与广大网友互动??

点此进行留言吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值