94

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
Ian Hunter
  • 9,466
  • 12
  • 61
  • 77
  • you'll have to update the mysql stuff as well. mysql-client or whatever. – Marc B May 25 '12 at 18:09
  • @MarcB I should have all of the latest versions of the MySQL suite (see my latest edit) – Ian Hunter May 25 '12 at 18:19
  • 1
    "Client API header" version cannot be upgraded because it is hardcoded into the PHP executable. They was the mysql headers (and libraries) installed on the PHP package mantainer's system at the time PHP was compiled. You cannot upgrade them. You have to fail back to MySQL 5.1.X libraries to make that version of PHP working again, or upgrade PHP to a version compiled with MySQL 5.5.X. – dAm2K May 26 '12 at 18:34
  • @dAm2K As it turned out the version *was* able to be upgraded by swapping out my current mysqli.so file with a newer one. – Ian Hunter May 26 '12 at 18:46
  • Sure! If you have mysql as external PHP module, you can try to just upgrade the mysql.so library. You should check that the new mysql.so it's 100% binary compatible with the version of PHP you have, or you may have problems very hard to debug (segmentation faults, invalid or corrupted results, and so on). The better way is to upgrade PHP to a version compiled with MySQL 5.5, or use the linux vendor's RPMs. – dAm2K May 26 '12 at 18:51
  • This may be a new question altogether, but do you know how I'd go about checking to see if it's completely compatible with my current version of PHP? So far nothing's blown up and the errors have gone away, but I certainly don't want anything screwy happening behind the scenes. – Ian Hunter May 26 '12 at 18:56
  • 1
    I really don't know if there is a way to check ABI compatibility... you just have to check apache error_log for strange httpd child errors. If after 3-4 days the error doesn't come, you should be ok. – dAm2K May 26 '12 at 22:06

14 Answers14

132

I am using MariaDB and have a similar problem.

From MariaDB site, it is recommended to fix it by

  1. Switch to using the mysqlnd driver in PHP (Recommended solution).
  2. Recompile PHP with the MariaDB client libraries.
  3. Use your original MySQL client library with the MariaDB.

My problem was fixed by using the mysqlnd driver in Ubuntu:

sudo apt-get install php5-mysqlnd

[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);
Dharman
  • 30,962
  • 25
  • 85
  • 135
ken
  • 13,869
  • 6
  • 42
  • 36
70

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
Timo Tijhof
  • 10,032
  • 6
  • 34
  • 48
  • 9
    Please explain your answer some. Things like what these packages do. – Machavity Aug 11 '14 at 16:19
  • 4
    For new MySQL 5.6 family you need to install php5-mysqlnd, not php5-mysql. – Carlos Buenosvinos Zamora Aug 15 '14 at 23:18
  • It solved the issue. I was facing this issue when I upgraded MySql (AWS RDS MySql Instance) from 5.5 to 5.6. – Rahul Prasad Dec 14 '14 at 10:00
  • 3
    Obviously restarting Apache is needed for this to work properly. Just pointing the obvious – Metafaniel May 20 '15 at 20:52
  • 1
    This broke my phpMyAdmin. Itseems phpMyAdmin can not work with MySQL native driver. – Dr. Ehsan Ali Aug 07 '15 at 21:39
  • ^^^ this did not *simply* work, ... gave error: `The following packages have unmet dependencies: libfontconfig1 : Breaks: xpdf (<= 3.03-11) but 3.03-10 is to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages`. Did not know how to revert back (after I removed php-mysql, it would not let me install it back). In the process of fixing this, had to update apache, fix apache config, and also update PHP to latest available stable versions and fix some other issues, like `perl: warning: Setting locale failed (LANGUAGE, LC_ALL)` – Dennis Jan 08 '16 at 18:12
32

Your PHP was compiled with MySQL 5.1 but now it is linking a mysql library of 5.5.X family. You have to upgrade PHP to a version compiled with MySQL 5.5 or revert back mysql client libraries to 5.1.x.

dAm2K
  • 9,923
  • 5
  • 44
  • 47
  • 1
    Basically this was the problem I was having, but rather than upgrade or downgrade anything, I was able to pull the mysqli.so file from a server with PHP compiled with MySQL 5.5 and just stick it in my /usr/lib/php5/ directory. I'm not sure it's the safest route to go, however, so I don't want to use that as the go-to answer. Thanks for your help. – Ian Hunter May 26 '12 at 18:42
23

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.

marek
  • 361
  • 2
  • 5
  • good fix for me, followed by sudo systemctl restart mysql sudo systemctl restart apache2 – Paul Jul 27 '16 at 06:10
  • It is much better to do the install and let the dependencies remove php5-mysql. Some systems do not like the purge of php5-mysql without an alternative. – Rui F Ribeiro Jun 08 '17 at 08:22
12

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.

Machavity
  • 30,841
  • 27
  • 92
  • 100
7

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.

Pumizo
  • 273
  • 2
  • 7
  • 16
2

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.

Sithsu
  • 2,209
  • 2
  • 21
  • 28
  • Your answer was so valuable to me. In it, I read that I had to use BOTH `--with-mysql` and `--with-mysqli` options to properly use the compiled driver. So I did again my configure command this time with: ` --with-mysql=/home/stephane/programs/mariadb/install \ --with-mysqli=/home/stephane/programs/mariadb/install/bin/mysql_config \` and the issue was solved. It now uses the correct MariaDB client version. – Stephane Nov 11 '16 at 13:55
1

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

user229044
  • 232,980
  • 40
  • 330
  • 338
OpenWebWar
  • 580
  • 8
  • 16
  • Just an FYI, this will stop working under PHP7 because the [mysql_ functions have been removed](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Apr 19 '16 at 14:28
1

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...

user229044
  • 232,980
  • 40
  • 330
  • 338
OpenWebWar
  • 580
  • 8
  • 16
1
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
Angel Politis
  • 10,955
  • 14
  • 48
  • 66
0

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.

Bob P
  • 1
0

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
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

Works for MariaDB 10.6.4-MariaDB, php56w, on centos 7.7

  1. yum remove php56w-mysqli
  2. yum install php56w-mysqlnd
cursorrux
  • 1,382
  • 4
  • 9
  • 20
-3

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.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136