MySQL ‘root’@’localhost’无法登录


今天早上同事说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 -pmysql>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 > statusConnection id: 639Current database: mysqlCurrent user: root@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: ”开发云主机域名Using delimiter: ;Server version: 5.6.15-log Source distributionProtocol version: 10Connection: Localhost via UNIX socket
mysql -h 127.0.0.1 > statusConnection id: 640Current database: mysqlCurrent user: root@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: ”Using delimiter: ;Server version: 5.6.15-log Source distributionProtocol version: 10Connection: 127.0.0.1 via TCP/IP

相关推荐: MySQL数据库总体架构讲义

本文主要给大家介绍MySQL数据库总体架构讲义,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在开发云行业资讯里面关注我的更新文章的。一、数据库的总体架构我们首先来看MySQL数据的总体架构如下:这是一张非常经典的MySQL的系统架构图,通过这…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 06/10 17:40
下一篇 06/10 17:40

相关推荐