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

您所在的位置:网站首页 Mysql安装时密码测试不过 mysql密码输入正确但是登陆不进去

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

2023-10-27 19:40| 来源: 网络整理| 查看: 265

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 © 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就解决问题了

转载于:https://blog.51cto.com/12449902/1893401



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3