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

[经验分享] ERROR 2049 (HY000): Connection using old (pre-4.1.1)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-11 13:49:20 | 显示全部楼层 |阅读模式
  测试环境新装了MySQL服务器,在登陆时无法成功登陆。其提示为使用的旧的认证协议而被拒绝。其具体的错误提示为ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)以下是关于这个问题的描述及其解决方案,供大家参考。
1、故障现象
[iyunv@HKBO ~]# mysqladmin -u root password 'Mysqlxxx'
[iyunv@HKBO ~]# mysql -uroot -p
Enter password:
ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)

[iyunv@HKBO ~]# mysql -uroot -p --skip-secure-auth
Enter password:
ERROR 1275 (HY000): Server is running in --secure-auth mode, but
'root'@'localhost' has a password in the old format; please change the password to the new format

2、有关secure_auth参数
  • --secure-auth

    Command-Line Format
    --secure-auth
    System Variable
    Name
    secure_auth
    Variable Scope
    Global
    Dynamic Variable
    Yes
    Permitted Values (<= 5.6.4)
    Type
    boolean
    Default
    OFF
    Permitted Values (>= 5.6.5)
    Type
    boolean
    Default
    ON

    This option causes the server to block connections by clients that attempt to use accounts that have passwords stored in the old (pre-4.1) format. Use it to prevent all use of passwords employing the old format (and hence insecure communication over the network). Before MySQL 5.6.5, this option is disabled by default. As of MySQL 5.6.5, it is enabled by default; to disable it, use --skip-secure-auth.

    Server startup fails with an error if this option is enabled and the privilege tables are in pre-4.1 format. SeeSection B.5.2.4, “Client does not support authentication protocol”.

    The mysql client also has a --secure-auth option, which prevents connections to a server if the server requires a password in old format for the client account.

  •     Note

        Passwords that use the pre-4.1 hashing method are less secure than passwords that use the native password hashing method and should be avoided. Pre-4.1 passwords are deprecated and support for them will be removed in a future MySQL release. Consequently, disabling secure authentication using --skip-secure-auth is also deprecated.



    3、分析及解决


        #查看当前的配置文件  
        [iyunv@HKBO ~]# grep -v ^# /etc/my.cnf   
        [mysqld]  
        datadir=/opt/data  
        socket=/tmp/mysql.sock  
        user=mysql  
        old_passwords=1     
          
        [mysqld_safe]  
        log-error=/var/log/mysqld.log  
        pid-file=/var/run/mysqld/mysqld.pid  
          
        #old_passwords  
        #This variable controls the password hashing method used by the PASSWORD() function.  
        #It also influences password hashing performed by CREATE USER and GRANT statements that specify a password using an IDENTIFIED BY clause.  
        #当值为1的使用正好使用的是Pre-4.1 (“old”) hashing mysql_old_password 旧密码方式,因此先将其禁用  
          
        [iyunv@HKBO ~]# vi /etc/my.cnf  
          
        #如下,禁用后的old_passwords  
        [iyunv@HKBO ~]# grep old_passwords /etc/my.cnf   
        #old_passwords=1  
          
        #重启mysql  
        [iyunv@HKBO ~]# service mysqld stop  
        Shutting down MySQL.[  OK  ]  
          
        [iyunv@HKBO ~]# service mysqld start  
        Starting MySQL..[  OK  ]  
          
        #登陆还是出现同样的提示  
        [iyunv@HKBO ~]# mysql -uroot -p  
        Enter password:   
        ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)  
          
        #下面尝试使用--secure_auth=off登陆,提示需要改变密码到新格式  
        [iyunv@HKBO ~]# mysql -uroot -p --secure_auth=off  
        Enter password:   
        ERROR 1275 (HY000): Server is running in --secure-auth mode, but 'root'@'localhost' has a password in the old format; please change the password to the new format  
          
        #下面我们增加secure-auth=off到配置文件  
        [iyunv@HKBO ~]# grep secure-auth /etc/my.cnf  
        secure-auth=off  
          
        #再次重启mysql  
        [iyunv@HKBO ~]# service mysqld stop  
        Shutting down MySQL.[  OK  ]  
        [iyunv@HKBO ~]# service mysqld start  
        Starting MySQL.[  OK  ]  
          
        #此时可以透过--secure_auth=off方式登陆  
        [iyunv@HKBO ~]# mysql -uroot -p --secure_auth=off  
        Enter password:   
        Welcome to the MySQL monitor.  Commands end with ; or \g.  
        Your MySQL connection id is 2  
        Server version: 5.6.12 Source distribution  
          
        Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
          
        Oracle is a 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> set password for 'root'@'localhost' =password('Mysqlxxx');  
        Query OK, 0 rows affected, 1 warning (0.01 sec)  
          
        mysql> exit  
        Bye  
          
        #通过上述操作后还是无法登陆,依旧需要使用--secure_auth=off方式才能登陆  
          
        #查看缺省的mysql客户端  
        [iyunv@HKBO ~]# which mysql  
        /app/soft/mysql/bin/mysql  
          
        [iyunv@HKBO ~]# /app/soft/mysql/bin/mysql -uroot -p  
        Enter password:   
        ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)  
          
        [iyunv@HKBO ~]# /app/soft/mysql/bin/mysql --version  
        /app/soft/mysql/bin/mysql  Ver 14.14 Distrib 5.6.12, for Linux (x86_64) using  EditLine wrapper  
          
        [iyunv@HKBO ~]# whereis mysql  
        mysql: /usr/bin/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz  
          
        #/usr/bin下也有一个mysql客户端,其版本为5.0.95  
        [iyunv@HKBO ~]# /usr/bin/mysql --version  
        /usr/bin/mysql  Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1  
          
        #经排查,当前主机有旧版的mysql  
        [iyunv@HKBO mysql]# rpm -qa | grep -i mysql  
        mysql-5.0.95-3.el5  
          
        #接下来卸载老版本的mysql  
        [iyunv@HKBO ~]# rpm -e --nodeps mysql-5.0.95-3.el5  
        warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave  
          
        [iyunv@HKBO ~]# find / -name mysql  
        /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql  
        /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql  
                       .........  
        /app/soft/mysql  
        /app/soft/mysql/bin/mysql  
        /app/soft/mysql/include/mysql  
        /var/lib/mysql  
        /var/spool/mail/mysql  
        /opt/data/mysql  
        /home/mysql  
        #移除旧版mysql的路径及其文件  
        [iyunv@HKBO ~]# rm -rf /var/lib/mysql     
          
        #考虑到配置文件的为旧版,直接用5.6.12版的缺省配置文件覆盖  
        [iyunv@HKBO ~]# cp /app/soft/mysql/support-files/my-default.cnf /etc/my.cnf  
        [iyunv@HKBO ~]# grep -v ^# /etc/my.cnf  
        [mysqld]  
        sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
          
        #重启mysql  
        [iyunv@HKBO ~]# service mysqld stop  
        Shutting down MySQL..[  OK  ]  
        [iyunv@HKBO ~]# service mysqld start  
        Starting MySQL.[  OK  ]  
          
        [iyunv@HKBO ~]# mysql -uroot -p --secure_auth=off  
        Enter password:   
          
        mysql> select user,host,password from mysql.user;  
        +------+--------------+------------------+   # Author : Leshami  
        | user | host         | password         |   # Blog   : http://blog.iyunv.com/leshami  
        +------+--------------+------------------+  
        | root | localhost    | 7ca9a8e40dd1bf23 |   #可以看到加密后的密码为16bit  
        +------+--------------+------------------+  
          
        mysql> set password for 'root'@'localhost'=password('Mysql66');  
        Query OK, 0 rows affected, 1 warning (0.00 sec)  
          
        mysql> select user,host,password from mysql.user where user='root';  
        +------+--------------+------------------+  
        | user | host         | password         |  
        +------+--------------+------------------+  
        | root | localhost    | 5614c1a44e6b0c87 |  #更新后还是16bit  
        +------+--------------+------------------+  
          
        #接下来尝试清空root密码  
        mysql> update mysql.user set password='' where user='root' and host='localhost';  
        Query OK, 1 row affected (0.02 sec)  
        Rows matched: 1  Changed: 1  Warnings: 0  
          
        #再一次重启mysql  
        [iyunv@HKBO ~]# service mysqld stop  
        Shutting down MySQL.[  OK  ]  
        [iyunv@HKBO ~]# service mysqld start  
        Starting MySQL.[  OK  ]  
          
        #接下来使用mysqladmin修改密码  
        [iyunv@HKBO ~]# mysqladmin -u root password 'xxx'  
          
        #此时可以成功登陆,且密码的密文明显变长,至此问题解决  
        [iyunv@HKBO ~]# mysql -uroot -p  
        Enter password:   
          
        mysql> select user,password,host from mysql.user;  
        +------+-------------------------------------------+--------------+  
        | user | password                                  | host         |  
        +------+-------------------------------------------+--------------+  
        | root | *3D56A309CD04FA2EEF181462E59011F075C89548 | localhost    |  
        +------+-------------------------------------------+--------------+  

    4、小结
    a、绝大多数情况下,MySQL缺省的my.cnf不靠谱,根据情况都需要适度修改。
    b、在安装MySQL之前应先检查当前主机是否存在旧版以及多实例(此次由于非生产环境,所以疏忽导致了这个问题)
    c、根据错误提示来定位故障原因,如此次的关键字为secure_auth
    d、理解有关secure_auth,old_passwords,skip-secure-auth参数的作用及其影响


运维网声明 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-37837-1-1.html 上篇帖子: mysql表之间的复制,同数据库 和不同数据库 下篇帖子: centos6,mysql 5.5 配置 master \ slave 数据同步备份
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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