使用php必然涉及到鏈接mysql數據庫,還沒遇到過單獨使用php的狀況,呵呵,也許我孤陋寡聞吧!php
1、在php4.x的時候,想讓php支持mysql很簡單,編譯時默認就是啓用的,如:mysql
./configure --prefix=/usr/local/php-4.4.9 --with-apxs2=/usr/sbin/apxs 便可支持mysqlsql
下面是configure幫助說明數據庫
--with-mysql[=DIR] Include MySQL support. DIR is the MySQL base directory.If unspecified, the bundled MySQL library will be used.
能夠看出,若是沒有指定DIR(mysql安裝目錄),將使用php源碼內部捆綁的MySql庫。bash
查看php源碼捆綁的mysql庫:ide
[root@localhost php-4.4.9]# ll ext/mysql/ 總用量 296 -rw-r--r-- 1 1000 1000 5516 7月 26 2005 config.m4 -rw-r--r-- 1 1000 1000 46 8月 21 2002 CREDITS drwxr-xr-x 2 1000 1000 12288 8月 18 04:35 libmysql -rw-r--r-- 1 1000 1000 8452 5月 23 2000 mysql.dsp -rw-r--r-- 1 1000 1000 4405 7月 12 2002 mysql.mak -rw-r--r-- 1 1000 1000 68195 12月 31 2007 php_mysql.c -rw-r--r-- 1 1000 1000 3743 12月 31 2007 php_mysql.h -rw-r--r-- 1 root root 182504 8月 18 04:35 php_mysql.lo lrwxrwxrwx 1 root root 12 8月 18 04:35 php_mysql.o -> php_mysql.lo
2、從php5.0.x到php5.2.x就不在php源碼內部捆綁mysql支持代碼了,主要是license問題,因此須要本身先安裝好mysql,而後在編譯php時指定mysql的安裝位置(其實就是libmysqlclient),來讓php支持mysql,在phper使用上卻是沒什麼,可是在編譯時,尤爲是想獨立安裝php(php-fpm)時特別不爽,由於還要先安裝好mysql,即便在本地不使用mysql。php-fpm
3、到php5.3.x的時候情況改變了,php團隊實現了本身的mysql驅動,即mysqlnd(MySQL native driver),這下好了,在編譯上和php4差很少了,不用再事先安裝好mysql了,而是php源碼內部就實現了支持mysql的代碼。優勢以下:性能
一、mysqlnd更容易編譯; 由於它是php源碼樹的一個組成部分測試
二、mysqlnd和php內部機制結合更緊密,是優化過的mysql驅動優化
三、mysqlnd更節省內存,從測試結果來看,比傳統的mysql擴展節省40%的內存
四、mysqlnd更快
五、mysqlnd提供了豐富的性能統計功能
六、mysqlnd使用了PHP license以免沒必要要的版權糾紛
4、到php5.4.x的時候已經默認啓用了mysqlnd
經過一個表格能夠更清晰的展示出來:
PHP 版本 | 默認 | 配置選項:mysqlnd | 配置選項:libmysql | 更新日誌 |
4.x.x | libmysql | 不適用 | --without-mysql to disable | MySQL enabled by default, MySQL client libraries are bundled |
5.0.x, 5.1.x, 5.2.x |
libmysql | 不適用 | --with-mysql=[DIR] | MySQL is no longer enabled by default, and the MySQL client libraries are no longer bundled |
5.3.x | libmysql | --with-mysql=mysqlnd | --with-mysql=[DIR] | mysqlnd is now available |
5.4.x | mysqlnd | --with-mysql | --with-mysql=[DIR] | mysqlnd is now the default |
總結:
下面是各種版本的編譯配置:
on php-4.x.x
./configure
on php-5.0.x - php-5.2.x
./configure --with-mysql=/usr/local/mysql-5.1.67
on php-5.3.x
./configure --with-mysql=mysqlnd
on php-5.4.x
./configure --with-mysql
歐耶,真是方便!