php中内置的mysql数据库连接驱动mysqlnd简介及mysqlnd的配置安装方式

来源:互联网 发布:詹姆斯09年对魔术数据 编辑:程序博客网 时间:2024/05/22 04:41

php中内置的mysql数据库连接驱动mysqlnd简介

   mysqlnd(MySQL Native Driver)是老版本中php的mysql连接库libmysqlclient( MySQL Client Library)的一个新的替代。mysqlnd从PHP 5.3.0开始就内置在官方发布的php源码包中。

   The MySQL database extensions MySQL extension, mysqli and PDO MYSQL all communicate with the MySQL server. In the past, this was done by the extension using the services provided by the MySQL Client Library. The extensions were compiled against the MySQL Client Library in order to use its client-server protocol. 

    With MySQL Native Driver there is now an alternative, as the MySQL database extensions can be compiled to use MySQL Native Driver instead of the MySQL Client Library. 

   MySQL Native Driver is written in C as a PHP extension. 


为什么要使用mysqlnd来替代原来的libmysql?主要原因有以下几个:

1. license问题

   libmysql是MYSQL AB公司开发的,现在已经是Oracle集团所属的了,它使用MYSQL license发布。

This ultimately led to MySQL support being disabled by default in PHP,

mysqlnd 是php的一部分,使用PHP license发布。

从此 license 的问题就算是解决了。

2.编译问题

   使用libmysql的时候,如果要正常编译php,必须首先安装好mysql。如果是单纯的一台WEB服务器,完全没必要装mysql。

mysqlnd的话,就不必安装mysql,直接可用。

3.性能问题

   由于mysqlnd是一个php扩展,使用了php memory management system,在内存使用方面效率相当高。

   举个例子:

使用libmysql的时候,mysql结果集中的每一行都在内存中储存了二次。

使用mysqlnd,结果集只会储存一次。

而且它还服从于php.ini中memory_limit的设置。


php中内置的mysql数据库连接驱动mysqlnd的新特性

1 改进的persistent connection。

2 特殊函数 mysqli_fetch_all(),只有安装了mysqlnd, mysqli中的这个函数才可用。

3 Performance statistics calls: mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats().

在分析性能瓶颈的时候,这些函数还是蛮好用的。

4 使用mysqlnd之后,mysqli也支持persistent connection了。这样看起来,mysqli受益最多。

5 PHP 5.3.3 之后,mysqlnd支持SSL。

6 PHP 5.3.2 之后,mysqlnd支持Compressed Protocol

7 PHP 5.3.4 之后,windows系统中的mysqlnd支持Named Pipes。



mysqlnd的配置安装方式,配置php的选项时加上以下附加项:


./configure --with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

[other options]


然后make,make install即可完成。



  • 转载请注明:文章转载自:[169IT-最新最全的IT资讯]
    本文标题:php中内置的mysql数据库连接驱动mysqlnd简介及mysqlnd的配置安装方式
0 0
原创粉丝点击