The MySQL Native Driver Plugin API is a feature of MySQL Native
plugins operate in the layer between PHP applications and the MySQL
server. This is comparable to MySQL Proxy. MySQL Proxy operates on a
layer between any MySQL client application, for example, a PHP
application and, the MySQL server.
can undertake typical MySQL Proxy tasks such as load balancing,
monitoring and performance optimizations. Due to the different
architecture and location,
mysqlnd plugins do not
have some of MySQL Proxy's disadvantages. For example, with plugins,
there is no single point of failure, no dedicated proxy server to
deploy, and no new programming language to learn (Lua).
mysqlnd plugin can be thought of as an extension
mysqlnd. Plugins can intercept the majority of
mysqlnd functions. The
functions are called by the PHP MySQL extensions such as
PDO_MYSQL. As a result, it is possible for a
mysqlnd plugin to intercept all calls made to these
extensions from the client application.
mysqlnd function calls can also be
intercepted, or replaced. There are no restrictions on manipulating
mysqlnd internal function tables. It is possible to
set things up so that when certain
functions are called by the extensions that use
mysqlnd, the call is directed to the appropriate
function in the
mysqlnd plugin. The ability to
mysqlnd internal function tables in this
way allows maximum flexibility for plugins.
Mysqlnd plugins are in fact PHP Extensions, written
in C, that use the
mysqlnd plugin API (which is
built into MySQL Native Driver,
can be made 100% transparent to PHP applications. No application
changes are needed because plugins operate on a different layer. The
mysqlnd plugin can be thought of as operating in a
The following list represents some possible applications of
Read/Write Splitting. An example of this is the PECL/mysqlnd_ms (Master Slave) extension. This extension splits read/write queries for a replication setup.
Round-Robin, least loaded
Query Auditing. An example of this is the PECL/mysqlnd_sip (SQL Injection Protection) extension. This extension inspects queries and executes only those that are allowed according to a ruleset.
Caching. An example of this is the PECL/mysqlnd_qc (Query Cache) extension.
Sharding. An example of this is the PECL/mysqlnd_mc (Multi Connect) extension. This extension will attempt to split a SELECT statement into n-parts, using SELECT ... LIMIT part_1, SELECT LIMIT part_n. It sends the queries to distinct MySQL servers and merges the result at the client.
MySQL Native Driver Plugins Available
There are a number of mysqlnd plugins already available. These include:
PECL/mysqlnd_mc - Multi Connect plugin.
PECL/mysqlnd_ms - Master Slave plugin.
PECL/mysqlnd_qc - Query Cache plugin.
PECL/mysqlnd_pscache - Prepared Statement Handle Cache plugin.
PECL/mysqlnd_sip - SQL Injection Protection plugin.
PECL/mysqlnd_uh - User Handler plugin.