4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP 4 / Mysql 5 の接続失敗

Last updated at Posted at 2014-02-10

古い環境移行でそのままという制約がありエラーになる。

使用環境

【WEBサーバー】

NAME VALUE
OS CentOS 5.10/64bit
PHP 4.3.11
MySQL-Client 5.0.95

【DBサーバー】

NAME VALUE
OS CentOS 5.10/64bit
MySQL-Server 5.0.95
MySQL-Client 5.0.95

設定

mysql.user
mysql> select Host, User, Password from mysql.user where user = 'root';
+--------------+------+-------------------------------------------+
| Host         | User | Password password('password')             |
+--------------+------+-------------------------------------------+
| 192.168.1.%  | root | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+--------------+------+-------------------------------------------+

接続テスト

connection(password-unmatch)
php -r "echo mysql_connect('192.168.1.2', 'root', '');"
# PHP Warning:  mysql_connect(): Access denied for user 'root'@'192.168.1.3' (using password: NO) in Command line code on line 1
connection(password-match)
php -r "echo mysql_connect('192.168.1.2', 'root', 'password');"
# PHP Warning:  mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in Command line code on line 1

処理条件

  1. /etc/my.cnf の変更可 : old_password=0 として設定済み
  2. mysql.user の変更不可 ( mysql root user 使用不可能 )
  3. PHPのバージョンアップ不可
  4. MySQLのバージョンアップ不可

別のサーバーでは動作していたらしいため動くはずなんだが動かない。(製作者行方知れず)

以下はできない
UPDATE mysql.user SET password = old_password('password') Where User = 'root';

どうも libmysql が古い場合にコレになるようだ。

実験(Yum から install )

yum -y install php
php -r "echo mysql_connect('', 'root', 'password');";
# PHP Warning:  mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in Command line code on line 1

yum から最新版をインストールした場合でも同現象は発生し

yum -y install php-mysql
php -r "echo mysql_connect('', 'root', 'password');";
# Resource id #2

yum から php-mysql をインストールした場合は 正常につながった。

ソースからインストール(コメント参考に)

wget http://*******/**/php.4.3.11.tar.gz
tar -zxf php.4.3.11.tar.gz
./configure --prefix=/usr/local/php4-test/ --with-mysql
# mysql を ソースからインストールした場合は
# ./configure --prefix=/usr/local/php4-test/ --with-mysql=$mysql_prefix
/usr/local/php4-test/bin/php -r "echo mysql_connect('', 'root', 'password');";
# Resource id #3

解決

原因としては 別の人が install していたのだが パッケージからインストールされた古い mysql が存在したためのようだ。ソースからインストールされた mysql が参照されていなかったため。

4
4
17

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?