mysql - old_password

 

 


在 PHP5.3 上連舊的 mysql 會有以下 Error:

Warning: mysql_pconnect(): Premature end of data (mysqlnd_wireprotocol.c:553) in
D:\Apache2.2\htdocs\test.php on line 2 Warning: mysql_pconnect(): OK packet 1 bytes shorter than expected in
D:\Apache2.2\htdocs\test.php on line 2 Warning: mysql_pconnect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.

mysql.connector:

mysql.connector.errors.NotSupportedError: Authentication with old (insecure) passwords is not supported.

原因:

MySQL supports two password encryption schemes, and yours are using the old legacy version.

Newer clients refuse to use those as they're pretty trivial to crack.

 


新舊 Password 的分別

 

# 16 characters = OLD  (ver < 4.1)
# 41 characters = New  (ver 4.1.1)

SELECT LENGTH(Password) FROM mysql.user

+------------+--------------------+
| user       | Length(`Password`) |
+------------+--------------------+
| root       |                 16 |
...

New Format:

  • start with "*"
  • 41 characters

 


Scope

 

old_passwords is both a global and a session variable

local:

SET old_passwords = 0;

global:

SET GLOBAL old_passwords=0;

option & my.cnf (Global)

Start mysqld with the --old-passwords option

相當於

old_passwords=1 in the my.cnf

 


更新舊 Password

 

在 mysql shell 內行

Set old_passwords=0;

UPDATE mysql.user SET Password = PASSWORD('testpass') WHERE User = 'testuser' limit 1;

FLUSH PRIVILEGES;

 

 

Creative Commons license icon Creative Commons license icon