PHP使用mysqlnd驱动
我的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自
我的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
原文地址:PHP使用mysqlnd驱动, 感谢原作者分享。