How to connect to a MySQL/MariaDB server with PHP using the dialog plugin.


January 2014.

Situation


You want to authenticate your MySQL/MariaDB users using an authentication plugin (for instance: pam). This kind of auth uses the dialog plugin. You can login using the mysql command line client and using Perl's DBI, but not without PHP.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client'

Solution


PHP now uses its own MySQL driver (mysqlnd), instead of the good old libmysqlclient.

The solution is to rebuild PHP using the right configure options.

--enable-pdo \
--with-mysqli=/usr/local/bin/mysql_config \
--with-pdo-mysql=/usr/local/bin/mysql_config \

Reference: http://dev.mysql.com/doc/apis-php/en/apis-php-mysqli.installation.linux.html