mysql old_password 更新

阿里云 centos 5.7, mysql-server 装好后,默认的配置文件/etc/my.cnf里面

old_password=1

从php连接mysql时会报错:

[01-Oct-2012 09:22:31 UTC] PHP Warning: PDO::__construct(): Premature end of data (mysqlnd_wireprotocol.c:553) in a.php on line 2
[01-Oct-2012 09:22:31 UTC] PHP Warning: PDO::__construct(): OK packet 9 bytes shorter than expected in a.php on line 2
[01-Oct-2012 09:22:31 UTC] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file' in a.php:2

解决办法:

  1. 修改/etc/my.cnf文件,并重启mysql server

    old_password=0
    
  2. 从mysql命令行更新旧的用户密码

    set password = password('yourpassword');
    

参考
参考
参考


Last modified on 2012-10-01