码迷,mamicode.com
首页 > 其他好文 > 详细

ERROR 2049 (HY000): Connection using old (pre-4.1.1)

时间:2014-12-09 17:29:25      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   使用   sp   for   strong   

测试环境新装了MySQL服务器,在登陆时无法成功登陆。其提示 为使用的旧的认证协议而被拒绝。其具体的错误提示为ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option ‘secure_auth‘ enabled)以下是关于这个问题的描述及其解决方案,供大家参考。

 

1、故障现象
[root@HKBO ~]# mysqladmin -u root password ‘Mysqlxxx‘
[root@HKBO ~]# mysql -uroot -p
Enter password:
ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option ‘secure_auth‘ enabled)

[root@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、分析及解决

    1. #查看当前的配置文件  
    2. [root@HKBO ~]# grep -v ^# /etc/my.cnf   
    3. [mysqld]  
    4. datadir=/opt/data  
    5. socket=/tmp/mysql.sock  
    6. user=mysql  
    7. old_passwords=1     
    8.   
    9. [mysqld_safe]  
    10. log-error=/var/log/mysqld.log  
    11. pid-file=/var/run/mysqld/mysqld.pid  
    12.   
    13. #old_passwords  
    14. #This variable controls the password hashing method used by the PASSWORD() function.  
    15. #It also influences password hashing performed by CREATE USER and GRANT statements that specify a password using an IDENTIFIED BY clause.  
    16. #当值为1的使用正好使用的是Pre-4.1 (“old”) hashing mysql_old_password 旧密码方式,因此先将其禁用  
    17.   
    18. [root@HKBO ~]# vi /etc/my.cnf  
    19.   
    20. #如下,禁用后的old_passwords  
    21. [root@HKBO ~]# grep old_passwords /etc/my.cnf   
    22. #old_passwords=1  
    23.   
    24. #重启mysql  
    25. [root@HKBO ~]# service mysqld stop  
    26. Shutting down MySQL.[  OK  ]  
    27.   
    28. [root@HKBO ~]# service mysqld start  
    29. Starting MySQL..[  OK  ]  
    30.   
    31. #登陆还是出现同样的提示  
    32. [root@HKBO ~]# mysql -uroot -p  
    33. Enter password:   
    34. ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option ‘secure_auth‘ enabled)  
    35.   
    36. #下面尝试使用--secure_auth=off登陆,提示需要改变密码到新格式  
    37. [root@HKBO ~]# mysql -uroot -p --secure_auth=off  
    38. Enter password:   
    39. 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  
    40.   
    41. #下面我们增加secure-auth=off到配置文件  
    42. [root@HKBO ~]# grep secure-auth /etc/my.cnf  
    43. secure-auth=off  
    44.   
    45. #再次重启mysql  
    46. [root@HKBO ~]# service mysqld stop  
    47. Shutting down MySQL.[  OK  ]  
    48. [root@HKBO ~]# service mysqld start  
    49. Starting MySQL.[  OK  ]  
    50.   
    51. #此时可以透过--secure_auth=off方式登陆  
    52. [root@HKBO ~]# mysql -uroot -p --secure_auth=off  
    53. Enter password:   
    54. Welcome to the MySQL monitor.  Commands end with ; or \g.  
    55. Your MySQL connection id is 2  
    56. Server version: 5.6.12 Source distribution  
    57.   
    58. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
    59.   
    60. Oracle is a registered trademark of Oracle Corporation and/or its  
    61. affiliates. Other names may be trademarks of their respective  
    62. owners.  
    63.   
    64. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.  
    65.   
    66. mysql> set password for ‘root‘@‘localhost‘ =password(‘Mysqlxxx‘);  
    67. Query OK, 0 rows affected, 1 warning (0.01 sec)  
    68.   
    69. mysql> exit  
    70. Bye  
    71.   
    72. #通过上述操作后还是无法登陆,依旧需要使用--secure_auth=off方式才能登陆  
    73.   
    74. #查看缺省的mysql客户端  
    75. [root@HKBO ~]# which mysql  
    76. /app/soft/mysql/bin/mysql  
    77.   
    78. [root@HKBO ~]# /app/soft/mysql/bin/mysql -uroot -p  
    79. Enter password:   
    80. ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option ‘secure_auth‘ enabled)  
    81.   
    82. [root@HKBO ~]# /app/soft/mysql/bin/mysql --version  
    83. /app/soft/mysql/bin/mysql  Ver 14.14 Distrib 5.6.12, for Linux (x86_64) using  EditLine wrapper  
    84.   
    85. [root@HKBO ~]# whereis mysql  
    86. mysql: /usr/bin/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz  
    87.   
    88. #/usr/bin下也有一个mysql客户端,其版本为5.0.95  
    89. [root@HKBO ~]# /usr/bin/mysql --version  
    90. /usr/bin/mysql  Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1  
    91.   
    92. #经排查,当前主机有旧版的mysql  
    93. [root@HKBO mysql]# rpm -qa | grep -i mysql  
    94. mysql-5.0.95-3.el5  
    95.   
    96. #接下来卸载老版本的mysql  
    97. [root@HKBO ~]# rpm -e --nodeps mysql-5.0.95-3.el5  
    98. warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave  
    99.   
    100. [root@HKBO ~]# find / -name mysql  
    101. /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql  
    102. /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql  
    103.                .........  
    104. /app/soft/mysql  
    105. /app/soft/mysql/bin/mysql  
    106. /app/soft/mysql/include/mysql  
    107. /var/lib/mysql  
    108. /var/spool/mail/mysql  
    109. /opt/data/mysql  
    110. /home/mysql  
    111. #移除旧版mysql的路径及其文件  
    112. [root@HKBO ~]# rm -rf /var/lib/mysql     
    113.   
    114. #考虑到配置文件的为旧版,直接用5.6.12版的缺省配置文件覆盖  
    115. [root@HKBO ~]# cp /app/soft/mysql/support-files/my-default.cnf /etc/my.cnf  
    116. [root@HKBO ~]# grep -v ^# /etc/my.cnf  
    117. [mysqld]  
    118. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
    119.   
    120. #重启mysql  
    121. [root@HKBO ~]# service mysqld stop  
    122. Shutting down MySQL..[  OK  ]  
    123. [root@HKBO ~]# service mysqld start  
    124. Starting MySQL.[  OK  ]  
    125.   
    126. [root@HKBO ~]# mysql -uroot -p --secure_auth=off  
    127. Enter password:   
    128.   
    129. mysql> select user,host,password from mysql.user;  
    130. +------+--------------+------------------+   # Author : Leshami  
    131. user | host         | password         |   # Blog   : http://blog.csdn.net/leshami  
    132. +------+--------------+------------------+  
    133. | root | localhost    | 7ca9a8e40dd1bf23 |   #可以看到加密后的密码为16bit  
    134. +------+--------------+------------------+  
    135.   
    136. mysql> set password for ‘root‘@‘localhost‘=password(‘Mysql66‘);  
    137. Query OK, 0 rows affected, 1 warning (0.00 sec)  
    138.   
    139. mysql> select user,host,password from mysql.user where user=‘root‘;  
    140. +------+--------------+------------------+  
    141. user | host         | password         |  
    142. +------+--------------+------------------+  
    143. | root | localhost    | 5614c1a44e6b0c87 |  #更新后还是16bit  
    144. +------+--------------+------------------+  
    145.   
    146. #接下来尝试清空root密码  
    147. mysql> update mysql.user set password=‘‘ where user=‘root‘ and host=‘localhost‘;  
    148. Query OK, 1 row affected (0.02 sec)  
    149. Rows matched: 1  Changed: 1  Warnings: 0  
    150.   
    151. #再一次重启mysql  
    152. [root@HKBO ~]# service mysqld stop  
    153. Shutting down MySQL.[  OK  ]  
    154. [root@HKBO ~]# service mysqld start  
    155. Starting MySQL.[  OK  ]  
    156.   
    157. #接下来使用mysqladmin修改密码  
    158. [root@HKBO ~]# mysqladmin -u root password ‘xxx‘  
    159.   
    160. #此时可以成功登陆,且密码的密文明显变长,至此问题解决  
    161. [root@HKBO ~]# mysql -uroot -p  
    162. Enter password:   
    163.   
    164. mysql> select user,password,host from mysql.user;  
    165. +------+-------------------------------------------+--------------+  
    166. user | password                                  | host         |  
    167. +------+-------------------------------------------+--------------+  
    168. | root | *3D56A309CD04FA2EEF181462E59011F075C89548 | localhost    |  
    169. +------+-------------------------------------------+--------------+ 

ERROR 2049 (HY000): Connection using old (pre-4.1.1)

标签:blog   http   io   ar   os   使用   sp   for   strong   

原文地址:http://www.cnblogs.com/yishujiayuan/p/4153613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!