[php] Headers and client library minor version mismatch

In PHP I'm getting the following warning whenever I try to connect to a database (via mysql_connect)

Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50162 Library:50524

In my php -i output I have the following values listed under mysqli

Client API library version => 5.5.24

Client API header version => 5.1.62

I've tried updating php5-mysql and php but I'm already at the latest version of both of them. How do I go about updating the header version so I stop seeing this warning?

EDIT

My MySQL files should all be updated to be the latest version:

$ apt-get install mysql.*5.5
. . .
mysql-client-5.5 is already the newest version.
mysql-server-core-5.5 is already the newest version.
mysql-server-5.5 is already the newest version.
mysql-testsuite-5.5 is already the newest version.
mysql-source-5.5 is already the newest version.

Removing old versions

$ apt-get remove mysql.*5.1
. . .
Package handlersocket-mysql-5.1 is not installed, so not removed
Package mysql-cluster-client-5.1 is not installed, so not removed
Package mysql-cluster-server-5.1 is not installed, so not removed
Package mysql-client-5.1 is not installed, so not removed
Package mysql-client-core-5.1 is not installed, so not removed
Package mysql-server-5.1 is not installed, so not removed
Package mysql-server-core-5.1 is not installed, so not removed
Package mysql-source-5.1 is not installed, so not removed

This question is related to php ubuntu mysqli warnings

The answer is


For new MySQL 5.6 family you need to install php5-mysqlnd, not php5-mysql.

Remove this version of the mysql driver

sudo apt-get remove php5-mysql

And install this instead

sudo apt-get install php5-mysqlnd

Warning: mysqli::mysqli(): Headers and client library minor version mismatch.
Headers:50547 Library:100026

I solved the above error by just rebuilding my Apache:

cPanel Version  56.0 (build 25)
Apache Version  2.4.18
PHP Version 5.5.30
MySQL Version   10.0.26-MariaDB

If u had access cpanel or whm for domain web hosting ...

In cPanel, Go to "Softwares and services" tab, >> and then click "Select PHP Version" >> set your desired version of php...

Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50547 Library:50628 in chennaitechnologies.com

Eg. Current PHP version:

PHP Version [5.2] ( list of 5.2, 5.3, 5.4, 5.5, 5.6 available php versions)

Warning: Changing php modules and php options via PHP Selector for native php version is impossible

I selected 5.6 php version, after that error cleared on my wordpress blog site...


My hosting company told me to fix this by deactivating "mysqli" and activating "nd_mysqli" in the php extensions.

The error is gone, but I don't have the knowledge to understand if this is the right method to fix this.


The root reason for this error is that PHP separated itself from the MySQL Client libraries some time ago. So what's happening (mainly on older compiles of linux) is that people will compile PHP against a given build of the MySQL Client (meaning the version of MySQL installed is irrelevant) and not upgrade (in CentOS this package is listed as mysqlclientXX, where XX represents the package number). This also allows the package maintainer to support lower versions of MySQL. It's a messy way to do it, but it was the only way given how PHP and MySQL use different licensing.

MySQLND solves the problem by using PHP's own native driver (the ND), which no longer relies on MySQL Client. It's also compiled for the version of PHP you're using. This is a better solution all around, if for no other reason that MySQLND is made to have PHP talk to MySQL.

If you can't install MySQLND you can actually safely ignore this error for the most part. It's just more of an FYI notice than anything. It just sounds scary.


I got same php warring in my wordpress site...

Err: Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50547 Library:50628 in /home/lhu/public_html/innovacarrentalschennai.com/wp-includes/wp-db.php on line 1515

Cause: I updated wp 4.2 to 4.5 version (PHP and MySql mismatch )

I changed wp-db.php on line 1515

$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );

to

if ( WP_DEBUG ) {
    $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
} else {
    $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
}

Its got without warring err on my wordpress site


I ran into the same issue on centos7. Removing php-mysql and installing php-mysqlnd fixed the problem. Thanks Carlos Buenosvinos Zamora for your suggestion.

Here are my commands on centos7 just in case this can be of help to anybody as most of the answers here are based on Debian/Ubuntu.

To find the installed php-mysql package

yum list installed | grep mysql

To remove the installed php-mysql package

yum remove php55w-mysql.x86_64

To install php-mysqlnd

yum install php-mysqlnd.x86_64

To compile php from source with MySQL native driver (mysqlnd),

cd /php/source/path
./configure <other-options> --with-mysql --with-mysqli --with-pdo-mysql
make clean    # required if there was a previous make, which could cause various errors during make
make
make install

From /php/source/path/configure --help.

--with-mysql=DIR        Include MySQL support.  DIR is the MySQL base
                      directory, if no DIR is passed or the value is
                      mysqlnd the MySQL native driver will be used
--with-mysqli=FILE      Include MySQLi support.  FILE is the path
                      to mysql_config.  If no value or mysqlnd is passed
                      as FILE, the MySQL native driver will be used
--with-pdo-mysql=DIR    PDO: MySQL support. DIR is the MySQL base directory
                      If no value or mysqlnd is passed as DIR, the
                      MySQL native driver will be used

One or more PHP MySQL extensions can be included by using these options.
If a value is not passed to these options, or if the value is mysqlnd, MySQL native driver will be used.


For WHM and cPanel, some versions need to explicty set mysqli to build.

Using WHM, under CENTOS 6.9 xen pv [dc] v68.0.27, one needed to rebuild Apache/PHP by looking at all options and select mysqli to build. The default was to build the deprecated mysql. Now the depreciation messages are gone and one is ready for future MySQL upgrades.


I have this problems when use Percona/MySQL 5.6 and the php driver was compiled with 5.5 and php5-mysql is required for some apps, so I write a script to rebuild the drivers.

https://github.com/falcacibar/php5-mysql-rebuild


Changing PHP version from 5.6 to 5.5 Fixed it.

You have to go to control panel > CGI Script and change PHP version there.


I am using MariaDB and have the similar problem.

From MariaDB site, it is recommended to fix it by

  1. Switch to using the mysqlnd driver in PHP (Recommended solution).
  2. Run with a lower error reporting level:

    $err_level = error_reporting(0);  
    $conn = mysql_connect('params');  
    error_reporting($err_level); 
    
  3. Recompile PHP with the MariaDB client libraries.
  4. Use your original MySQL client library with the MariaDB.

My problem fixed by using the mysqlnd driver in Ubuntu:

sudo apt-get install php5-mysqlnd

Cheers!


[update: extra information] Installing this driver also resolve PDO problem that returns integer value as a string. To keep the type as integer, after installing mysqlInd, do this

$db = new PDO('mysql:host='.$host.';dbname='.$db_name, $user, $pass, 
          array( PDO::ATTR_PERSISTENT => true));
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);

The same works for MySQL:

sudo apt-get install php5-mysqlnd

I've read this thread trying to find the solution for MySQL, and I've also seen ken's answer, but I ignored the solution for MariaDB, wasting a few hours that way. It wasn't clear for me that the same may apply to MySQL. This post is just to spare you the few hours I lost.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to mysqli

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) mysqli_real_connect(): (HY000/2002): No such file or directory mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it Call to a member function fetch_assoc() on boolean in <path> How can I enable the MySQLi extension in PHP 7? Fatal error: Call to a member function bind_param() on boolean Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\ How to check if a row exists in MySQL? (i.e. check if an email exists in MySQL) Object of class mysqli_result could not be converted to string in mysqli::query(): Couldn't fetch mysqli

Examples related to warnings

numpy division with RuntimeWarning: invalid value encountered in double_scalars libpng warning: iCCP: known incorrect sRGB profile How to use _CRT_SECURE_NO_WARNINGS C pointers and arrays: [Warning] assignment makes pointer from integer without a cast Server configuration by allow_url_fopen=0 in IntelliJ IDEA shows errors when using Spring's @Autowired annotation Warning :-Presenting view controllers on detached view controllers is discouraged Data truncated for column? Warning message: In `...` : invalid factor level, NA generated How to suppress warnings globally in an R Script