登录mysql的登不进去_mysql密码输入正确但是登陆不进去

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

root账户缺失了访问localhost主机的账户信息,导致无法本地登录。

[root@228827 ~]# mysql -uroot -p123456

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

密码正确的情况下,mysql数据库已经禁止了root用户在本地的登录权限了。

使用root用户通过主机127.0.0.1登录就可以正常进入mysql,127.0.0.1和localhost对mysql数据库来讲是不同的主机,

[root@228827 ~]# mysql -uroot -p123456 -h 127.0.0.1

这让我想起了mysql下的user表。

我们要进mysql看user表,一种方法可以通过上面的命令,如果不行,可以用下面的命令启动数据库,缺省密码进入

代码如下

[root@228827 ~]# /etc/init.d/mysql stop

[root@228827 ~]# /usr/local/mysql/bin/mysqld_safe –skip-grant-tables &

[root@228827 ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 1

Server version: 5.1.57 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> use mysql

Database changed

mysql> select user,host,password from user where user='root';

+——+——————-+——————————————-+

| user | host | password |

+——+——————-+——————————————-+

| root | % | *A50E066E106320CF4142 |

| root | centos | *A50E066E106320CF4142 |

| root | 127.0.0.1 | *A50E066E1063608320CF4142 |

+——+——————-+——————————————-+

3 rows in set (0.12 sec)

发现user表host字段中没有localhost,但是我的理解是%代表所有的主机都能登录的,为什么localhost不能呢,同样的情况我在5.0.45版的mysql上面做实验就不会发生localhost无法登录,我当前用的是5.1.57版的,难道是版本的问题?

接下来的修改很明显了:

代码如下

mysql> update user set host='localhost' where user='root' and host='%';

mysql> flush privileges;

OK,退出mysql,重启mysql就解决问题了

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值