设为首页 收藏本站
查看: 743|回复: 0

[经验分享] 关于root(其他)用户拒绝登陆mysql的处理方法

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-9-18 09:16:01 | 显示全部楼层 |阅读模式
1.1.   关于root(其他)用户拒绝登陆的处理方法

问题描述:

[iyunv@gflinux3 mysql-install]# mysql -uroot-p

Enter password:

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

1.1.1.      跳过权限表登陆

         (1)重启数据库,跳过权限表方式登陆:

[iyunv@gflinux3 mysql-install]# /etc/init.d/mysqldstart --skip-grant-table

Starting MySQL.........                                    [  OK  ]

[iyunv@gflinux3 mysql-install]# mysql -uroot

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

Your MySQL connection id is 1

Server version: 5.5.37-log Sourcedistribution


Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved.


Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.


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

mysql>

         (2)更该root密码

mysql> update user set host='%' whereuser='root' and password ='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';

Query OK, 0 rows affected (0.01 sec)

Rows matched: 1  Changed: 0 Warnings: 0


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

         (3)重启数据库并重新登陆

[iyunv@gflinux3 mysql-install]#service mysqlrestart

         如果问题还是不能解决,继续向下看。

1.1.2.      远程可以本地无法登陆

         本地无法登陆,但是远程或者其他用户可以登陆,root无法登陆。

[iyunv@gflinux3 mysql-install]# mysql -urgf-p

Enter password:

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

         (1)查看user表中分布用户

mysql> select user,host,password from user;

+------+------+----------------------------------------------------------------------------+

| user | host          | password                                                                       |

+------+------+----------------------------------------------------------------------------+

| root | %             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | gflinux3    |

| root | 127.0.0.1 |

| root | ::1           |

| rgf  | %              | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+------+------+---------------------------------------------------------------------------+

2 rows in set (0.00 sec)

         (2)查看文件/etc/hosts

[iyunv@gflinux3 mysql-install]# vi/etc/hosts


# Do not remove the following line, orvarious programs

# that require network functionality willfail.

127.0.0.1      gflinux3 localhost.localdomain localhost

::1            localhost6.localdomain6 localhost6

192.168.6.103   gflinux3

         (3)分析

         mysql初始化时root用户根据hosts配置文件中的主机及主机名在user表中产生上述记录(127.0.0.1,gflinux3,localhost,::1,192.168.6.103),而安装完数据库,使用mysqladmin初始化密码时,是对user表中localhost,即上述表中第一条记录做的修改:

mysql> select user,host,password from user;

+------+------+----------------------------------------------------------------------------+

| user | host          | password                                                                       |

+------+------+----------------------------------------------------------------------------+

| root | localhost   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+------+------+---------------------------------------------------------------------------+

         而其他“主机”密码都为空,这时再以root及其密码登陆时当然无法登陆。

         更值得提醒的时,这些“主机”的存在,在安全上及其危险。

         (4)处理方法

         首先,修改hosts文件为:

[iyunv@gflinux3 mysql-install]# vi/etc/hosts


# Do not remove the following line, orvarious programs

# that require network functionality willfail.

127.0.0.1      gflinux3 localhost.localdomain localhost

#::1           localhost6.localdomain6 localhost6

192.168.6.103   gflinux3

         其次,删除user表中所有相关主机记录。

mysql>delete  from user where hostin('gflinux3','127.0.0.1','::1','localhost');

Query OK,5 rows affected (0.01 sec)


mysql>update privileges;


mysql>select user,host,password from user;

+------+------+-------------------------------------------+

| user |host | password                                  |

+------+------+-------------------------------------------+

| root |%    |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

|rgf  | %    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|

+------+------+-------------------------------------------+

2 rows inset (0.00 sec)

         (3)登陆验证

[iyunv@gflinux3mysql-install]# mysql -uroot -p

Enterpassword:

Welcometo the MySQL monitor.  Commands end with; or g.

YourMySQL connection id is 22

Serverversion: 5.5.37-log Source distribution


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


Oracle isa registered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

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


mysql>

         当然,不建议使root用户从远程连接,这样很危险,因此,作如下操作取消使用root远程连接:

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

Query OK,1 row affected (0.00 sec)

Rowsmatched: 1  Changed: 1  Warnings: 0


mysql>flush privileges;

Query OK,0 rows affected (0.00 sec)

1.1.3.      关于登陆

         (1)如果host字段更新为localhost:

         如下方式可以登陆成功:

[iyunv@gflinux3mysql-install]# mysql -uroot -p

[iyunv@gflinux3mysql-install]# mysql -hlocalhost -uroot -p

         但是如下方式无法登陆:

[iyunv@gflinux3mysql-install]# mysql -h127.0.0.1 -uroot -p

[iyunv@gflinux3mysql-install]# mysql -h gflinux3 -uroot -p

[iyunv@gflinux3mysql-install]# mysql -h192.168.6.103 -uroot -p

         原因是user表中host字段值只有记录localhost。其他登陆方式无法在user表中得到认证。

         (2)如果host字段更新为%

         所有的方式都可以登陆:

[iyunv@gflinux3mysql-install]# mysql -uroot -p

[iyunv@gflinux3mysql-install]# mysql -hlocalhost -uroot -p

[iyunv@gflinux3mysql-install]# mysql -h127.0.0.1      -uroot -p

[iyunv@gflinux3mysql-install]# mysql -h gflinux3 -uroot -p

[iyunv@gflinux3mysql-install]# mysql -h192.168.6.103 -uroot -p

         原因是user表中host字段值匹配所有主机。(127.0.0.1,gflinux3,localhost,::1,192.168.6.103)这些都是指的一台主机,在user表中可以通过认证,从而可以登陆。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-25010-1-1.html 上篇帖子: 实时检查MySQL数据库延迟状况复制中断数据延迟 下篇帖子: mysql中source用法一瞥 mysql 用户
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表