2016年4月15日金曜日

今週のハマった事件(MYSQL)

今週のハマった事件

PHP 5.3.xからMySQLに接続できない

PHPを最新版にソースからインストールしたところ、下記互換が無くなって、PHPからMySQLに接続できなくなった。
この場合、以下のようなエラーメッセージが発生します。
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

PHP 5.2.xから5.3.xの下位互換性のない変更点

状況としては、開発に使用していたMySQLのデータベースでバージョン4.1以前にも対応できる古い形式のパスワード (16バイトのもの) を使用していたため、それに対応していないPHP 5.3.5のmysqlndから接続できなかったというものでした。
対処としては、php側では回避する方法がないので、MySQL側のパスワード設定を変更して対応します。
この例では、hostというサーバのwordpressというユーザーのパスワードをhogehogeに設定します。

# sudo /etc/init.d/mysqld stop
# sudo vi /etc/my.cnf
下記の行があれば削除します。
 old_passwords=1
# sudo /etc/init.d/mysqld stop
# sudo mysql -u root -p
 password: rootのDBパスワード
 mysql>set password for 'wordpress'@'localhost' = password('hogehoge');

0 件のコメント:

コメントを投稿