MySQL includes a test plugin that checks account credentials and logs success or failure to the server error log. This is a loadable plugin (not built in) and must be installed prior to use.
The test plugin source code is separate from the server source, unlike the built-in native plugin, so it can be examined as a relatively simple example demonstrating how to write a loadable authentication plugin.
This plugin is intended for testing and development purposes, and is not for use in production environments or on servers that are exposed to public networks.
The following table shows the plugin and library file names. The
file name suffix might differ on your system. The file must be
located in the directory named by the
plugin_dir system variable. For
installation information, see
Section 6.3.7, “Pluggable Authentication”.
Table 6.16 Plugin and Library Names for Test Authentication
|Server-side plugin name|
|Client-side plugin name|
|Library file name|
The following sections provide installation and usage information specific to test pluggable authentication:
For general information about pluggable authentication in MySQL, see Section 6.3.7, “Pluggable Authentication”.
This section describes how to install the test authentication plugin. For general information about installing plugins, see Section 5.5.2, “Installing and Uninstalling Plugins”.
To be usable by the server, the plugin library file must be
located in the MySQL plugin directory (the directory named by
variable). If necessary, set the value of
plugin_dir at server startup
to tell the server the plugin directory location.
To load the plugin at server startup, use the
--plugin-load-add option to
name the library file that contains it. With this
plugin-loading method, the option must be given each time the
server starts. For example, put these lines in your
Alternatively, to register the plugin at runtime, use this statement (adjust the extension as necessary):
INSTALL PLUGIN test_plugin_server SONAME 'auth_test_plugin.so';
INSTALL PLUGIN loads a plugin,
and also registers it in the
table to cause the plugin to be loaded for each subsequent
normal server startup.
To verify plugin installation, examine the
or use the
Section 5.5.3, “Obtaining Server Plugin Information”). For example:
SELECT PLUGIN_NAME, PLUGIN_STATUS
WHERE PLUGIN_NAME LIKE '%test_plugin%';+--------------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | +--------------------+---------------+ | test_plugin_server | ACTIVE | +--------------------+---------------+
If the plugin fails to initialize, check the server error log for diagnostic messages.
To associate a MySQL account with the test plugin, use the
test_plugin_server in the
IDENTIFIED WITH clause of the
CREATE USER statement that
creates the account. (See
Using Test Pluggable Authentication.)
The method used to uninstall the test authentication plugin depends on how you installed it:
If you installed the plugin at server startup using a
--plugin-load-addoption, restart the server without the option.
UNINSTALL PLUGIN test_plugin_server;
To use the test authentication plugin, create an account and
name that plugin in the
CREATE USER 'testuser'@'localhost' IDENTIFIED WITH test_plugin_server BY 'testpassword';
mysql --user=testuser --passwordEnter password:
The plugin fetches the password as received from the client
and compares it with the value stored in the
authentication_string column of the account
row in the
mysql.user table. If the two
values match, the plugin returns the
authentication_string value as the new
effective user ID.
You can look in the server error log for a message indicating whether authentication succeeded (notice that the password is reported as the “user”):
[Note] Plugin test_plugin_server reported: 'successfully authenticated user testpassword'