天天看點

php使用mysqlnd引發的一些問題處理

現在CentOS 5.11使用的仍是比較老舊的mysql 5.0.59 伺服器版本,PHP也是使用的最高的也是5.3.3(使用yum -y install php53安裝)。從官方看5.3的最後一個版本為5.3.29已經于2014年8月份停止支援,出現的一些bug及安全性問題将會得不到修複,是以我們決定将PHP的版本更新到5.5。在安裝的時候我們使用

1

<code>.</code><code>/configure</code> <code>--prefix=</code><code>/data/php</code><code>.5.5.26 --with-bz2 --with-curl --</code><code>enable</code><code>-</code><code>ftp</code> <code>--</code><code>enable</code><code>-sockets --disable-ipv6 --with-gd  --with-iconv-</code><code>dir</code><code>=</code><code>/data/libiconv</code> <code>--</code><code>enable</code><code>-mbstring --</code><code>enable</code><code>-calendar --with-gettext --with-zlib --with-mcrypt --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --</code><code>enable</code><code>-dom --</code><code>enable</code><code>-xml --</code><code>enable</code><code>-fpm --with-fpm-user=www --with-fpm-group=www</code>

可以看到我們使用了mysqlnd作為連接配接資料庫的驅動。可以在測試的過程中出現了一些問題。

将代碼部署到測試伺服器的時間出現No such file or directory,檢查nginx日志出現PHP message: PHP Warning:  mysql_connect(): No such file or directory。經過檢查發現原來是mysqlnd連接配接不到資料庫,修改php的配置檔案mysql.default_socket = /var/lib/mysql/mysql.sock  注意我這邊是yum安裝的mysql server,重新啟動php-fpm.如果你使用的是apache的話則啟動apache的服務即可。

使用mysql_connect('localhost','root','123')發現伺服器又報錯

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

使用mysqlnd的時候,有個地方需要注意。就是服務端的密碼格式不能使用舊的16位的存儲格式,而要使用新的41位的存儲格式

2

3

4

5

6

7

8

<code>mysql&gt; </code><code>select</code> <code>user,length(password) from mysql.user;</code>

<code>+----------+------------------+</code>

<code>| user     | length(password) |</code>

<code>| root     |               16 |</code>

<code>| </code><code>test</code>     <code>|               16 |</code>

<code>2 rows </code><code>in</code> <code>set</code> <code>(0.00 sec)</code>

第一、更改資料庫的配置檔案/etc/my.conf

在[mysqld]下檢查是否有

[mysqld]

old_passwords=1 

将其更改為

old_passwords=0

如果沒有新增之,然後重新啟動資料庫服務

第二、更改資料庫的密碼

9

10

11

12

13

14

<code>update mysql.user </code><code>set</code> <code>password=password(</code><code>'123456'</code><code>) where user=</code><code>'root'</code><code>;</code>

<code>update mysql.user </code><code>set</code> <code>password=password(</code><code>'123456'</code><code>) where user=</code><code>'test'</code><code>;</code>

<code>flush privileges;   </code>

<code>+--------------+------------------+</code>

<code>| user         | length(password) |</code>

<code>| root         |               41 | </code>

<code>| </code><code>test</code>         <code>|               41 | </code>

<code>+--------------+------------------+  </code>

<code>這個更改密碼看你有使用幾個使用者了。</code>

再次重新整理網頁,正常了了。

本文轉自 rong341233 51CTO部落格,原文連結:http://blog.51cto.com/fengwan/1662046