mysql密码输入正确但是登陆不进去
2017-01-20 13:55
323 查看
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就解决问题了
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就解决问题了
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- Android之获取手机上的图片和视频缩略图thumbnails
- 访问Nginx发生SSL connection error的一种情况
- 异常:javax.el.PropertyNotFoundException: Property 'mainGroupCode' not found on type java.lang.String
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- 数据库链接字符串查询网站
- 解决mysql 开启logbin 导致存储过程报错
- MySQL 备份和恢复策略
- mac下安装mysql(转载)