Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to make a plugin

Plugin API reference: How to make a plugin . Generated from the MariaDB server headers by doxygen and moxygen.

This is a tutorial and a walk-through on how to bootstrap, implement, compile, test and distribute a MariaDB Plugin Library.

Architecture and Design Decisions.

The most important architectural decision is to decide what Plugin API to implement. To make that determination you need to understand when your plugin needs to be called by the server and with what parameters.

Sometimes just the base st_maria_plugin API is good enough. st_maria_plugin::init is called when the plugin is loaded and st_maria_plugin::deinit is called when the plugin is unloaded. This will suffice if you are after implementing e.g. a network listener: you can start a background thread that listens for connections and processes connects, disconnects and commands in st_maria_plugin::init. And then signal to it to shut down gracefully from st_maria_plugin::deinit.

In this case you implement the so called Daemon Plugin. This has no API whatsoever. Just a version.

But, in general, you need to understand the available Plugin Types and decide on implementing the one that suits your needs best.

Do you want to provide a better password validation method? Look into Password Validation Plugin. Need to expose data in tabular format to server? Do a Information Schema Plugin.

The good part is that you can actually combine multiple Plugin into a single Plugin Library.

So, back to the example above, if you need to implement a network listener, but also return the current connection table as an INFORMATION_SCHEMA table you can define the two Plugin implementations into your single Plugin Library.

Code your plugin library

It's easiest to just take one of the existing plugins and copy its code.

But, in case you want to start afresh, here's a very minimal boilerplate to copy from

#include <mysql/plugin.h>
/* TODO: if needed: #include <mysql/specific plugin type, e.g. plugin_audit.h> */

static int plugin_one_init(void *)
{
  /* TODO: code here */
  return 0; /* success */
}

static int plugin_one_deinit(void *)
{
  /* TODO: code here */
  return 0; /* success */
}

static struct st_mysql_daemon plugin_one =
{ MYSQL_DAEMON_INTERFACE_VERSION  };

maria_declare_plugin(plugin_one)
{
  MYSQL_DAEMON_PLUGIN,
  &plugin_one,
  "plugin example",
  "You",
  "A boilerplate plugin code",
  PLUGIN_LICENSE_GPL,
  plugin_one_init,            /* Plugin Init */
  plugin_one_deinit,          /* Plugin Deinit */
  0x0100,                     /* 1.0 */
  NULL,                       /* status variables */
  NULL,                       /* system variables */
  "1.0",                      /* string version */
  MariaDB_PLUGIN_MATURITY_EXPERIMENTAL /* maturity */
}
maria_declare_plugin_end;

See also: maria_declare_plugin, maria_declare_plugin_end, MYSQL_DAEMON_PLUGIN, MYSQL_DAEMON_INTERFACE_VERSION, PLUGIN_LICENSE_GPL, MariaDB_PLUGIN_MATURITY_EXPERIMENTAL

If you need to add system variables, you can add the following to the above:

And then pass on the sysvars to the maria_declare_plugin 's system variable placeholder.

See also: MYSQL_SYSVAR_UINT, mysql_var_check_func, mysql_var_update_func, MYSQL_SYSVAR

Similarly, if you need status variables, you can add the following:

And then pass on the status_vars to the maria_declare_plugin 's status variable placeholder.

See also: st_mysql_show_var, SHOW_INT

This page is licensed: GPLv2

Last updated

Was this helpful?