mysqli_connectでエラー

mysql_connectがPHP 5.5から非推奨になるためmysqli_connectを使ってとあったので使ってみると、以下のようにエラーになることがある。

$ php -r “mysqli_connect(‘localhost’,’user’,’password’,’dbname’);”
PHP Warning: mysqli_connect(): Premature end of data (mysqlnd_wireprotocol.c:553) in Command line code on line 1
PHP Warning: mysqli_connect(): OK packet 1 bytes shorter than expected in Command line code on line 1
PHP Warning: mysqli_connect(): (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 Command line code on line 1

old_passwordが有効になっていると接続できないらしい。

/etc/my.confを開き、

old_passwords=0

になっていることを確認し、必要に応じて

mysql> set password for ‘user’@’localhost’ = PASSWORD(‘password’);

でパスワードを生成しなおす必要がある。

The following two tabs change content below.

taira

Sofrware Engineer.

Comments are closed.