PHP使用mysqlnd驅動的配置詳解

來源:互聯網
上載者:User

我的PHP環境是5.4,使用mysql時突然出現以下錯誤:

mysql_connect(): Headers and client library minor version mismatch. Headers:50508 Library:50166

索性換成mysqlnd擴充,下面簡單介紹mysqlnd:


mysqlnd(MySQL native driver for PHP)是php5.3後php內建的mysql驅動,官方推薦使用,優勢如下:
A.libmysql驅動是由mysql AB公司(現在是oracle公司)編寫, 並按mysql license許可協議發布,所以在PHP中預設是被禁用的.

而mysqlnd是由php官方開發的驅動,以php license許可協議發布,故就規避了許可協議和著作權的問題

B.因為mysqlnd內建於PHP原始碼,故你在編譯安裝php時就不需要預先安裝mysql server也可以提供mysql client API (mysql_connect, pdo , mysqli), 這將減化一些工作量.

C. mysqlnd是專門為php最佳化編寫的驅動,它使用了PHP本身的特性,在記憶體管理,效能上比libmysql更有優勢. php官方的測試是:libmysql將每條記錄在記憶體中儲存了兩份,而mysqlnd只儲存了一份

D. 一些新的或增強功能

增強持久串連

引入特有的函數mysqli_fetch_all()

引入一些效能統計函數 mysqli_get_cache_stats(), mysqli_get_client_stats(),

mysqli_get_connection_stats(),

使用上述函數,可很容易分析mysql查詢的效能瓶頸!

SSL支援(從php 5.3.3開始有效)

壓縮協議支援

具名管道支援(php 5.4.0開始有效)

如何使用mysqlnd驅動?
傳統的編譯php時帶如下參數:
--with-mysql=/usr/local/mysql

--with-pdo-mysql=/usr/local/mysql

查看編譯參數:


[root@localhost php54]#./configure --help | grep mysql
  --with-mysql=DIR      Include MySQL support.  DIR is the MySQL base
                          mysqlnd the MySQL native driver will be used
  --with-mysql-sock=SOCKPATH   MySQL/MySQLi/PDO_MYSQL: Location of the MySQL unix socket pointer.
  --with-mysqli=FILE    Include MySQLi support.  FILE is the path
                          to mysql_config.  If no value or mysqlnd is passed
  --enable-embedded-mysqli  MYSQLi: Enable embedded support
  --with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                                 If no value or mysqlnd is passed as DIR, the
  --enable-mysqlnd        Enable mysqlnd explicitly, will be done implicitly
  --disable-mysqlnd-compression-support
                            Disable support for the MySQL compressed protocol in mysqlnd
  --with-zlib-dir=DIR       mysqlnd: Set the path to libz install prefix

可以看到只要不指定,預設就是mysqlnd。於是重新編譯PHP:


./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap--with-mysql --with-pdo-mysql --with-mysqli

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.