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

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS AI 助手,专业版
简介:     测试环境新装了MySQL服务器,在登陆时无法成功登陆。其提示为使用的旧的认证协议而被拒绝。其具体的错误提示为ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)以下是关于这个问题的描述及其解决方案,供大家参考。

    测试环境新装了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、分析及解决

#查看当前的配置文件
[root@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 旧密码方式,因此先将其禁用

[root@HKBO ~]# vi /etc/my.cnf

#如下,禁用后的old_passwords
[root@HKBO ~]# grep old_passwords /etc/my.cnf 
#old_passwords=1

#重启mysql
[root@HKBO ~]# service mysqld stop
Shutting down MySQL.[  OK  ]

[root@HKBO ~]# service mysqld start
Starting MySQL..[  OK  ]

#登陆还是出现同样的提示
[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)

#下面尝试使用--secure_auth=off登陆,提示需要改变密码到新格式
[root@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到配置文件
[root@HKBO ~]# grep secure-auth /etc/my.cnf
secure-auth=off

#再次重启mysql
[root@HKBO ~]# service mysqld stop
Shutting down MySQL.[  OK  ]
[root@HKBO ~]# service mysqld start
Starting MySQL.[  OK  ]

#此时可以透过--secure_auth=off方式登陆
[root@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客户端
[root@HKBO ~]# which mysql
/app/soft/mysql/bin/mysql

[root@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)

[root@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

[root@HKBO ~]# whereis mysql
mysql: /usr/bin/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

#/usr/bin下也有一个mysql客户端,其版本为5.0.95
[root@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
[root@HKBO mysql]# rpm -qa | grep -i mysql
mysql-5.0.95-3.el5

#接下来卸载老版本的mysql
[root@HKBO ~]# rpm -e --nodeps mysql-5.0.95-3.el5
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave

[root@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的路径及其文件
[root@HKBO ~]# rm -rf /var/lib/mysql   

#考虑到配置文件的为旧版,直接用5.6.12版的缺省配置文件覆盖
[root@HKBO ~]# cp /app/soft/mysql/support-files/my-default.cnf /etc/my.cnf
[root@HKBO ~]# grep -v ^# /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

#重启mysql
[root@HKBO ~]# service mysqld stop
Shutting down MySQL..[  OK  ]
[root@HKBO ~]# service mysqld start
Starting MySQL.[  OK  ]

[root@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.csdn.net/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
[root@HKBO ~]# service mysqld stop
Shutting down MySQL.[  OK  ]
[root@HKBO ~]# service mysqld start
Starting MySQL.[  OK  ]

#接下来使用mysqladmin修改密码
[root@HKBO ~]# mysqladmin -u root password 'xxx'

#此时可以成功登陆,且密码的密文明显变长,至此问题解决
[root@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参数的作用及其影响

鹏城DBA总群

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
Linux 网络安全 开发工具
CentOS openssh 升级教程
低版本和centos系统默认安装的openssh版本经常会有高风险漏洞,因此openssh需要保持升级到最新版本。
2619 0
|
监控 算法 测试技术
性能优化之几种常见压测模型及优缺点 | 陈显铭
上一篇讲的是《性能优化的常见模式及趋势》,今天接着讲集中常见的压测模型。通过上一章我们大概知道了性能优化的一些招式,但是怎么发现有性能问题,常见的模式还是需要压测。
6115 0
|
网络协议 网络安全 数据安全/隐私保护
|
传感器 存储 SQL
Flink多流转换(Flink Stream Unoin、Flink Stream Connect、Flink Stream Window Join)
Flink多流转换(Flink Stream Unoin、Flink Stream Connect、Flink Stream Window Join)
Flink多流转换(Flink Stream Unoin、Flink Stream Connect、Flink Stream Window Join)
|
存储 传感器 算法
西门子 PCS 7 系统结构
西门子 SIMATIC PCS 7 系统是现代 DCS 的一个实例(分布式控制系统),它采用了当前的LAN (局域网) 技术、久经考验的西门子 PLC(可编程序控制器)和现场总线技术。整个系统由大量的西门子硬件组件组成,包括仪表、执行机构、模拟和数字信号模块,控制器、通讯处理器、工程师站和操作员站等。所有硬件组件由 PCS 7 软件工具支持和组态。
西门子 PCS 7 系统结构
|
分布式计算 MaxCompute BI
【转载】时隔一年多,我又用起了 Superset
去年 6 月份在流利说提离职后,leader 问我为什么要走。我说,流利说有很健全的数据处理基础设施,但这不是所有的公司都会有的条件,所以我想看看在一个基建不全的创业公司我是否也可以像现在一样做的好。
18113 82
|
存储 Java 开发工具
Android C++系列:JNI基本操作
自从 Android Studio 使用 CMake 进行编译就方便多了,不需要再写 Android.mk 了,也不需要用 javah 来生成头文件了,直接写好 native 方法,快捷方式就可以生成对应的 C++ 方法,只要专注写好 C++ 代码,CMake 就可以指定的 CPU 架构生成对应的 SO 库。
439 0
|
SQL 存储 关系型数据库
新特性|MySQL 8.0 GIPK 不可见主键
### 一 前言 作为MySQL DBA ,相信大家都经历过在复制模式下,如果没有主键,遇到load data,大事务,ddl 等有大量表数据行扫描的行为时,会带来严重的主从延迟,给数据库稳定性和数据一致性带来隐患。 MySQL 8.0.30 已于近日GA,新版本为我们提供了一个令人惊喜的特性 -(Generated Invisible Primary Keys)简称GIPK 。一句概况就是:
640 0
新特性|MySQL 8.0 GIPK 不可见主键
|
Kubernetes 安全 容器
ASM单点登录(一)ASM + Keycloak实现网格内应用单点登录
作为业内首个全托管Istio兼容的阿里云服务网格产品ASM,一开始从架构上就保持了与社区、业界趋势的一致性,控制平面的组件托管在阿里云侧,与数据面侧的用户集群独立。ASM产品是基于社区Istio定制实现的,在托管的控制面侧提供了用于支撑精细化的流量管理和安全管理的组件能力。通过托管模式,解耦了Istio组件与所管理的K8s集群的生命周期管理,使得架构更加灵活,提升了系统的可伸缩性。从2022年4月
919 0
ASM单点登录(一)ASM + Keycloak实现网格内应用单点登录
|
弹性计算 监控 BI
抢占式实例最佳实践——如何选择出价模式
本文为您介绍新的组合方案&quot;SpotAsPriceGo+OOSPriceMonitor&quot;,在帮助您有效降低中断概率的同时,又能保障价格不会偏离您的预期值,帮助您合理控制成本。
抢占式实例最佳实践——如何选择出价模式

热门文章

最新文章