我在尝试连接 5.1.xx 等较低版本的 MySQL 时,在使用最新的 MySQL 客户端 (>5.7) 时遇到了同样的问题。
为避免此问题(ERROR 2027 (HY000): Malformed packet),请使用最新密码验证创建用户。
例如:
登录 MySQL 5.1.xx 服务器并执行..
mysql> create user 'testuser'@'xx.xx.xxx.%' identified by 'testuser_Secret1';
检查您是否启用了 old_passwords,然后为该会话禁用它。
mysql> show session variables like 'old_passwords';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| old_passwords | ON |
+-----------------+-------+
mysql> set session old_passwords = 0;
mysql> GRANT select on test.* TO 'testuser'@'xx.xx.xxx.%' identified by 'testuser_Secret1';
验证应以“*SOMETHING1123SHOWNBELOW3034”开头的密码。
mysql> select user,host,password from mysql.user where user = 'testuser';
+-----------+---------------+-------------------------------------------+
| user | host | password |
+-----------+---------------+-------------------------------------------+
| testuser | xx.xx.xxx.% | *053CB27FDD2AE63F03D4A0B919E471E0E88DA262 |
+-----------+---------------+-------------------------------------------+
现在尝试从 MySQL 5.7.xx 客户端登录并尝试建立与 MySQL 5.1.xx 服务器的连接。
[testuser@localhost]# mysql -V
mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
[testuser@localhost]# mysql -hxx.xx.xxx.xxx -u testuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1528853
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2020, 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>